-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
97 lines (77 loc) · 3.13 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import joblib
from flask import Flask, jsonify, request , render_template
import pandas as pd
import numpy as np
import json
data = data = {
'employee_id': 74430,
'department': 'HR',
'region': 'region_4',
'education': 'Bachelors',
'gender': 'f',
'recruitment_channel': 'other',
'no_of_trainings': 1,
'age': 31,
'previous_year_rating': 3.0,
'length_of_service': 5,
'KPIs_met_more_than_80': 0,
'awards_won': 0
}
#lets conect to our template
app = Flask(__name__)
app.json.sort_keys = False
@app.route("/")
def hello():
return render_template('index.html')
@app.route('/predict', methods=['POST','GET'])
def predict():
content = request.form
request_data = json.loads(json.dumps(content))
print(request_data)
employee_id = content.get('employee_id')
department = content.get('department')
region = content.get('region')
education = content.get('education')
gender = content.get('gender')
recruitment_channel = content.get('recruitment_channel')
no_of_trainings = content.get('no_of_trainings')
age = content.get('age')
previous_year_rating = content.get('previous_year_rating')
length_of_service = content.get('length_of_service')
KPIs_met_more_than_80 = content.get('KPIs_met_more_than_80')
awards_won = content.get('awards_won')
# result = {
# 'employee_id': int(employee_id),
# 'department': str(department),
# 'region': region,
# 'education': education,
# 'gender': gender,
# 'recruitment_channel': recruitment_channel,
# 'no_of_trainings': int(no_of_trainings),
# 'age': int(age),
# 'previous_year_rating': float(previous_year_rating),
# 'length_of_service': int(length_of_service),
# 'KPIs_met_more_than_80': int(KPIs_met_more_than_80),
# 'awards_won': int(awards_won),
# }
result={
"employee_id": int(employee_id),
"department": department,
"region": region,
"education": education,
"gender": gender,
"recruitment_channel": recruitment_channel,
"no_of_trainings": int(no_of_trainings),
"age": int(age),
"previous_year_rating": float(previous_year_rating),
"length_of_service": int(length_of_service),
"KPIs_met_more_than_80": int(KPIs_met_more_than_80),
"awards_won": int(awards_won)
}
df=pd.DataFrame([result])
model=joblib.load('production_pipelineV3.pkl')
prediction=model.predict(df)
prediction = int(prediction[0])
return render_template('result.html',employee_id=employee_id,department=department,region=region,education=education,gender=gender,recruitment_channel=recruitment_channel,no_of_trainings=no_of_trainings,age=age,previous_year_rating=previous_year_rating,length_of_service=length_of_service,KPIs_met_more_than_80=KPIs_met_more_than_80,awards_won=awards_won,prediction=prediction)
if __name__ == '__main__':
app.run(debug=True)