-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
60 lines (43 loc) · 1.58 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
from flask import Flask, escape, request, render_template
import pickle
from sklearn.preprocessing import StandardScaler
import numpy as np
scaler = StandardScaler()
model = pickle.load(open("Stroke_model.pkl", 'rb'))
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/collect_data')
def collect_data():
return render_template('data.html')
@app.route('/result', methods=['POST', 'GET'])
def predict():
if request.method =="POST":
gender = request.form['gender']
age = int(request.form['age'])
hypertension = int(request.form['hypertension'])
disease = int(request.form['heart_disease'])
glucose = float(request.form['avg_glucose_level'])
smoking = request.form['smoking_status']
# gender
gender_male, gender_female = 0,0
if (gender == "Male"):
gender_male=1
elif(gender == "Female"):
gender_female = 1
# smoking status
never_smoked, formely_smoked = 0,0
if(smoking=='never smoked'):
never_smoked = 1
elif smoking=='formerly smoked':
formely_smoked = 1
X = np.array([gender_male, gender_female, age, hypertension, disease, glucose, formely_smoked, never_smoked])
# feature = scaler.fit_transform([X])
print(X)
prediction = model.predict([X])[0]
return render_template("result.html", prediction_text=prediction)
else:
return render_template("result.html")
if __name__ == "__main__":
app.run(debug=True)