-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (50 loc) · 1.52 KB
/
app.py
File metadata and controls
63 lines (50 loc) · 1.52 KB
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
from flask import Flask, render_template, request
import joblib
import os
import numpy as np
import pickle
app = Flask(__name__)
@app.route("/")
def index():
return render_template("home.html")
@app.route("/result", methods=["POST", "GET"])
def result():
gender = int(request.form["gender"])
age = int(request.form["age"])
hypertension = int(request.form["hypertension"])
heart_disease = int(request.form["heart_disease"])
ever_married = int(request.form["ever_married"])
work_type = int(request.form["work_type"])
Residence_type = int(request.form["Residence_type"])
avg_glucose_level = float(request.form["avg_glucose_level"])
bmi = float(request.form["bmi"])
smoking_status = int(request.form["smoking_status"])
x = np.array(
[
gender,
age,
hypertension,
heart_disease,
ever_married,
work_type,
Residence_type,
avg_glucose_level,
bmi,
smoking_status,
]
).reshape(1, -1)
scaler_path = "new-models/scaler.pkl"
scaler = None
with open(scaler_path, "rb") as scaler_file:
scaler = pickle.load(scaler_file)
x = scaler.transform(x)
model_path = "new-models/dt.sav"
dt = joblib.load(model_path)
Y_pred = dt.predict(x)
# for No Stroke Risk
if Y_pred == 0:
return render_template("nostroke.html")
else:
return render_template("stroke.html")
if __name__ == "__main__":
app.run(debug=True, port=7384)