-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
74 lines (50 loc) · 1.96 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
from flask import Flask, render_template, request, flash, redirect
import pickle
import numpy as np
app = Flask(__name__)
def predict(values):
if len(values) == 8:
to_predict = np.array(values).reshape(1, 8)
loaded_model = pickle.load(open("models/diabetes.pkl", "rb"))
result = loaded_model.predict(to_predict)
return result[0]
elif len(values) == 13:
to_predict = np.array(values).reshape(1, 13)
loaded_model = pickle.load(open("models/heart.pkl", "rb"))
result = loaded_model.predict(to_predict)
return result[0]
elif len(values) == 18:
to_predict = np.array(values).reshape(1, 18)
loaded_model = pickle.load(open("models/kidney.pkl", "rb"))
result = loaded_model.predict(to_predict)
return result[0]
elif len(values) == 10:
to_predict = np.array(values).reshape(1, 10)
loaded_model = pickle.load(open("models/liver.pkl", "rb"))
result = loaded_model.predict(to_predict)
return result[0]
@ app.route("/")
def home():
return render_template('home.html')
@ app.route("/diabetes", methods=['GET', 'POST'])
def diabetesPage():
return render_template('diabetes.html')
@ app.route("/heart", methods=['GET', 'POST'])
def heartPage():
return render_template('heart.html')
@ app.route("/kidney", methods=['GET', 'POST'])
def kidneyPage():
return render_template('kidney.html')
@ app.route("/liver", methods=['GET', 'POST'])
def liverPage():
return render_template('liver.html')
@ app.route("/predict", methods=['GET', 'POST'])
def predictPage():
if request.method == 'POST':
to_predict_list = request.form.to_dict()
to_predict_list = list(to_predict_list.values())
to_predict_list = list(map(float, to_predict_list))
pred = predict(to_predict_list)
return render_template('predict.html', pred=pred)
if __name__ == '__main__':
app.run(host='localhost', port=5000, debug=True)