-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (47 loc) · 2.41 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
# import numpy as np
from flask import Flask, request, jsonify, render_template
import pandas as pd
import json
import pickle
from flask import make_response
app = Flask(__name__)
with open('model.pkl', 'rb') as f:
model = pickle.load(f)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
req = request.get_json(silent=True, force=True)
print('Request: ')
print(json.dumps(req['queryResult']['parameters'], indent=4))
int_features = json.dumps(req['queryResult']['parameters'], indent=4)
int_features = json.loads(int_features)
final_features = pd.DataFrame(
{'age': [float(int_features['age']['amount']) / 80], 'bp': [float(int_features['bp']) / 10],
'al': [float(int_features['al']) / 5], 'pcc': [float(int_features['pcc'])],
'bgr': [float(int_features['bgr']) / 146], 'bu': [float(int_features['bu']) / 418],
'sod': [float(int_features['sod']) / 164], 'pot': [float(int_features['pot']) / 130.1],
'hemo': [float(int_features['hemo']) / 21.7], 'rbcc': [float(int_features['rbcc']) / 12.8],
'dm': [float(int_features['dm'])], 'appet': [float(int_features['appet'])]})
prediction = model.predict(final_features)
print(prediction[0][0])
pred = (prediction[0][0] * 0.96)
if pred > 0.75:
result_prediction = 'Don\'t worry you have ' + str((
1 - pred) * 100) + '% precentage to have chronicle kidney disease. We have 99.06% confident for say that !! '
elif (pred > 0.5):
result_prediction = 'You are in some denger zone. You have ' + str((
1 - pred) * 100) + '% percentae to have chronicle kidney disease. We have 99.06% confident for say that !! Care full'
else:
result_prediction = 'You are in very danger zone. You have ' + str((
1 - pred) * 100) + '% percentae to have chronicle kidney disease. We have 99.06% confident for say that !! Meet your doctor as soon as possible'
res = {
"fulfillmentText": result_prediction
}
res = json.dumps(res, indent=4)
r = make_response(res)
r.headers['Content-Type'] = 'application/json'
return r
if __name__ == "__main__":
app.run(debug=True)