-
Notifications
You must be signed in to change notification settings - Fork 8
/
main_file.py
58 lines (43 loc) · 1.43 KB
/
main_file.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
# Author: SimpleSaad
from flask import Flask, render_template, url_for, request
import joblib
import os
import numpy as np
import pickle
app = Flask(__name__, static_folder='static')
@app.route("/")
def index():
return render_template('home.html')
@app.route('/result', methods=['POST', 'GET'])
def result():
age = int(request.form['age'])
sex = int(request.form['sex'])
trestbps = float(request.form['trestbps'])
chol = float(request.form['chol'])
restecg = float(request.form['restecg'])
thalach = float(request.form['thalach'])
exang = int(request.form['exang'])
cp = int(request.form['cp'])
fbs = float(request.form['fbs'])
x = np.array([age, sex, cp, trestbps, chol, fbs, restecg,
thalach, exang]).reshape(1, -1)
scaler_path = os.path.join(os.path.dirname(__file__), 'models/scaler.pkl')
scaler = None
with open(scaler_path, 'rb') as f:
scaler = pickle.load(f)
x = scaler.transform(x)
model_path = os.path.join(os.path.dirname(__file__), 'models/rfc.sav')
clf = joblib.load(model_path)
y = clf.predict(x)
print(y)
# No heart disease
if y == 0:
return render_template('nodisease.html')
# y=1,2,4,4 are stages of heart disease
else:
return render_template('heartdisease.htm', stage=int(y))
@app.route('/about')
def about():
return render_template('about.html')
if __name__ == "__main__":
app.run(debug=True)