-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
88 lines (77 loc) · 2.11 KB
/
server.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
from pyrebase import pyrebase
from flask import Flask, request, jsonify
import pandas as pd
import pickle
config = {
"apiKey": "AIzaSyCfEjJpkUdFooIkdqdRj_TZng1imrmymMY",
"authDomain": "my-portfolio-248515.firebaseapp.com",
"databaseURL": "https://my-portfolio-248515.firebaseio.com",
"projectId": "my-portfolio-248515",
"storageBucket": "my-portfolio-248515.appspot.com",
"messagingSenderId": "970529353485",
"appId": "1:970529353485:web:529efcd5de1ede64"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
app = Flask(__name__)
@app.route("/", methods=['POST'])
def formInput():
model = pickle.load(
open("../Model.pickle", 'rb')
)
x = request.get_json()
# y = model.predict([list(map(float, x.values()))])
print(type(x))
val = []
val.append(int(x['age']))
val.append(int(x['family_history'] == 'No'))
d = {
'Somewhat easy': 1,
"Don't know": 1.5,
'Very easy': 0,
'Somewhat difficult': 2,
'Very difficult': 3
}
val.append(d[x['leave']])
d = {
'often': 3,
'never': 0,
'sometimes': 7,
'rarely': 5
}
val.append(d[x['work_interfere']])
val.append(int(x['benefits'] == 'No'))
val.append(int(x['anonymity'] == 'No'))
d = {
'No': 0,
'Yes': 1,
"Don't know": 1.5
}
val.append(d[x['phys_health_consequence']])
val.append(d[x['mental_health_interview']])
val.append(int(x['obs_consequence'] == 'No'))
print(val)
val2 = []
val2.append(val)
y = model.predict_proba(val2)
y = y[0][0]
data = {
"age":val[0],
"family_history":val[1],
"leave":val[2],
"work_interfere":val[3],
"benefits":val[4],
"anonymity":val[5],
"phys_health_consequence":val[6],
"mental_health_interview":val[7],
"obs_consequence":val[8],
"prediction":y
}
db.child("monthly_data").push(data)
y1 = jsonify({
"prediction": y
}) # Data snapshot
return y1
if __name__ == '__main__':
print("Running")
app.run(debug=True)