Spaces:
Sleeping
Sleeping
Merge pull request #8 from anshusandhi6/master
Browse files- README.md +7 -4
- app.py +41 -0
- model.pkl +0 -0
- static/css/style.css +59 -0
- templates/index.html +36 -0
README.md
CHANGED
@@ -3,9 +3,12 @@ This is project predicts the salary of the employee based on the experience.
|
|
3 |
|
4 |
# Model
|
5 |
model.py trains and saves the model to the disk.
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
3 |
|
4 |
# Model
|
5 |
model.py trains and saves the model to the disk.
|
6 |
+
model.pkb the pickle model
|
7 |
|
8 |
+
# App
|
9 |
+
app.py contains all the requiered for flask and to manage APIs.
|
10 |
|
11 |
+
|
12 |
+
|
13 |
+
Procedure--
|
14 |
+
Open command Prompt and go to given directory and then run python app.py
|
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from flask import Flask, request, jsonify, render_template
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
model = pickle.load(open('model.pkl', 'rb'))
|
7 |
+
|
8 |
+
@app.route('/')
|
9 |
+
def home():
|
10 |
+
return render_template('index.html')
|
11 |
+
|
12 |
+
@app.route('/predict',methods=['POST'])
|
13 |
+
def predict():
|
14 |
+
'''
|
15 |
+
For rendering results on HTML GUI
|
16 |
+
'''
|
17 |
+
int_features = [int(x) for x in request.form.values()]
|
18 |
+
final_features = [np.array(int_features)]
|
19 |
+
prediction = model.predict(final_features)
|
20 |
+
|
21 |
+
output = round(prediction[0], 2)
|
22 |
+
|
23 |
+
return render_template('index.html', prediction_text='Salary is {}'.format(output))
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
@app.route('/predict_api',methods=['POST'])
|
30 |
+
def predict_api():
|
31 |
+
'''
|
32 |
+
For direct API calls trought request
|
33 |
+
'''
|
34 |
+
data = request.get_json(force=True)
|
35 |
+
prediction = model.predict([np.array(list(data.values()))])
|
36 |
+
|
37 |
+
output = prediction[0]
|
38 |
+
return jsonify(output)
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
app.run(debug=True)
|
model.pkl
ADDED
Binary file (515 Bytes). View file
|
|
static/css/style.css
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
|
2 |
+
.btn { display: inline-block; *display: inline; *zoom: 1; padding: 4px 10px 4px; margin-bottom: 0; font-size: 13px; line-height: 18px; color: #333333; text-align: center;text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75); vertical-align: middle; background-color: #f5f5f5; background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6); background-image: -ms-linear-gradient(top, #ffffff, #e6e6e6); background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6)); background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6); background-image: -o-linear-gradient(top, #ffffff, #e6e6e6); background-image: linear-gradient(top, #ffffff, #e6e6e6); background-repeat: repeat-x; filter: progid:dximagetransform.microsoft.gradient(startColorstr=#ffffff, endColorstr=#e6e6e6, GradientType=0); border-color: #e6e6e6 #e6e6e6 #e6e6e6; border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); border: 1px solid #e6e6e6; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); cursor: pointer; *margin-left: .3em; }
|
3 |
+
.btn:hover, .btn:active, .btn.active, .btn.disabled, .btn[disabled] { background-color: #e6e6e6; }
|
4 |
+
.btn-large { padding: 9px 14px; font-size: 15px; line-height: normal; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; }
|
5 |
+
.btn:hover { color: #333333; text-decoration: none; background-color: #e6e6e6; background-position: 0 -15px; -webkit-transition: background-position 0.1s linear; -moz-transition: background-position 0.1s linear; -ms-transition: background-position 0.1s linear; -o-transition: background-position 0.1s linear; transition: background-position 0.1s linear; }
|
6 |
+
.btn-primary, .btn-primary:hover { text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); color: #ffffff; }
|
7 |
+
.btn-primary.active { color: rgba(255, 255, 255, 0.75); }
|
8 |
+
.btn-primary { background-color: #4a77d4; background-image: -moz-linear-gradient(top, #6eb6de, #4a77d4); background-image: -ms-linear-gradient(top, #6eb6de, #4a77d4); background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#6eb6de), to(#4a77d4)); background-image: -webkit-linear-gradient(top, #6eb6de, #4a77d4); background-image: -o-linear-gradient(top, #6eb6de, #4a77d4); background-image: linear-gradient(top, #6eb6de, #4a77d4); background-repeat: repeat-x; filter: progid:dximagetransform.microsoft.gradient(startColorstr=#6eb6de, endColorstr=#4a77d4, GradientType=0); border: 1px solid #3762bc; text-shadow: 1px 1px 1px rgba(0,0,0,0.4); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.5); }
|
9 |
+
.btn-primary:hover, .btn-primary:active, .btn-primary.active, .btn-primary.disabled, .btn-primary[disabled] { filter: none; background-color: #4a77d4; }
|
10 |
+
.btn-block { width: 100%; display:block; }
|
11 |
+
|
12 |
+
* { -webkit-box-sizing:border-box; -moz-box-sizing:border-box; -ms-box-sizing:border-box; -o-box-sizing:border-box; box-sizing:border-box; }
|
13 |
+
|
14 |
+
html { width: 100%; height:100%; }
|
15 |
+
|
16 |
+
body {
|
17 |
+
width: 100%;
|
18 |
+
height:1000px;
|
19 |
+
font-family: 'Open Sans', sans-serif;
|
20 |
+
background: #092756;
|
21 |
+
color: #fff;
|
22 |
+
font-size: 18px;
|
23 |
+
text-align:center;
|
24 |
+
letter-spacing:1.2px;
|
25 |
+
overflow-y: scroll !important;
|
26 |
+
overflow-x: hidden;
|
27 |
+
|
28 |
+
}
|
29 |
+
.login {
|
30 |
+
position: absolute;
|
31 |
+
top: 5%;
|
32 |
+
left:38%;
|
33 |
+
|
34 |
+
width:400px;
|
35 |
+
height:800px;
|
36 |
+
}
|
37 |
+
|
38 |
+
.login h1 { color: #fff; text-shadow: 0 0 10px rgba(0,0,0,0.3); letter-spacing:1px; text-align:center; }
|
39 |
+
|
40 |
+
input {
|
41 |
+
width: 100%;
|
42 |
+
margin-bottom: 10px;
|
43 |
+
background: rgba(0,0,0,0.3);
|
44 |
+
border: none;
|
45 |
+
outline: none;
|
46 |
+
padding: 10px;
|
47 |
+
font-size: 13px;
|
48 |
+
color: #fff;
|
49 |
+
text-shadow: 1px 1px 1px rgba(0,0,0,0.3);
|
50 |
+
border: 1px solid rgba(0,0,0,0.3);
|
51 |
+
border-radius: 4px;
|
52 |
+
box-shadow: inset 0 -5px 45px rgba(100,100,100,0.2), 0 1px 1px rgba(255,255,255,0.2);
|
53 |
+
-webkit-transition: box-shadow .5s ease;
|
54 |
+
-moz-transition: box-shadow .5s ease;
|
55 |
+
-o-transition: box-shadow .5s ease;
|
56 |
+
-ms-transition: box-shadow .5s ease;
|
57 |
+
transition: box-shadow .5s ease;
|
58 |
+
}
|
59 |
+
input:focus { box-shadow: inset 0 -5px 45px rgba(100,100,100,0.4), 0 1px 1px rgba(255,255,255,0.2); }
|
templates/index.html
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html >
|
3 |
+
<!--From https://codepen.io/frytyler/pen/EGdtg-->
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<title>ML API</title>
|
7 |
+
<link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
|
8 |
+
<link href='https://fonts.googleapis.com/css?family=Arimo' rel='stylesheet' type='text/css'>
|
9 |
+
<link href='https://fonts.googleapis.com/css?family=Hind:300' rel='stylesheet' type='text/css'>
|
10 |
+
<link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
|
11 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
12 |
+
|
13 |
+
</head>
|
14 |
+
|
15 |
+
<body>
|
16 |
+
<div class="login">
|
17 |
+
<div>
|
18 |
+
|
19 |
+
</div>
|
20 |
+
|
21 |
+
<!-- Main Input For Receiving Query to our ML -->
|
22 |
+
<form action="{{ url_for('predict')}}"method="post">
|
23 |
+
<input type="text" name="YearsExperience" placeholder="YearsExperience" required="required" />
|
24 |
+
|
25 |
+
<button type="submit" class="btn btn-primary btn-block btn-large">Predict</button>
|
26 |
+
</form>
|
27 |
+
|
28 |
+
<br>
|
29 |
+
<br>
|
30 |
+
{{ prediction_text }}
|
31 |
+
|
32 |
+
</div>
|
33 |
+
|
34 |
+
|
35 |
+
</body>
|
36 |
+
</html>
|