-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
165 lines (139 loc) · 4.7 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import flask
from flask import request, render_template, jsonify, redirect
import numpy as np
from predictor_api import predict_outcome
# from model_api import
# from predictor_api import predict_outcome
app = flask.Flask(__name__)
@app.route("/")
def main():
return redirect('static/html/index.html', code=302)
@app.route("/request", methods= ['POST'])
def result():
if request.method == 'POST':
age = int(request.form.get('age'))
sex = request.form.get('male')
sex_raw = sex
if sex == "Male":
sex = 1
else:
sex = 0
sysBP = float(request.form.get('sysBP'))
totCHO = float(request.form.get('totChol'))
glucose = float(request.form.get('glucose'))
bmi = float(request.form.get('BMI'))
restingHR = float(request.form.get('heartRate'))
cigs = float(request.form.get('cigsPerDay'))
education = request.form.get('education')
education_raw = education
if education == "Some High School":
education = 1
elif education == "High School Diploma":
education = 2
elif education == "College Diploma":
education = 3
else:
education = 4
bpMed = request.form.get('BPMeds')
bpMed_raw = bpMed
if bpMed == "Yes":
bpMed = 1
else:
bpMed = 0
stroke = request.form.get('prevalentStroke')
stroke_raw = stroke
if stroke == "Yes":
stroke = 1
else:
stroke = 0
form_data = []
form_data.append((age, sex, sysBP, totCHO, glucose, bmi, restingHR, cigs, education, bpMed, stroke))
form_data = form_data[0]
print(form_data)
# invoke predict_outcome
# CHD_risk = predict_outcome(form_data)
#if CHD_risk == 1:
#print("you are at high risk of heart disease")
#else:
#print("you are not at high risk of heart disease")
# print(np.array(form_data))
ml_result = predict_outcome(np.array(form_data).reshape(-1,11))
# print(result)
#age
if (age >= 65):
non_ml_age = "Increased Risk"
else:
non_ml_age = "Lower Risk"
#sex
if (sex_raw == "Male"):
non_ml_sex = "Increased Risk"
else:
non_ml_sex = "Lower Risk"
#sysBP
if (sysBP < 120):
non_ml_bp = (0, "Low Risk")
elif (sysBP >= 120 and sysBP <= 129):
non_ml_bp = (0, "Increased Risk")
else:
non_ml_bp = (1, "High Risk")
#cholesterol levels
if (totCHO <= 200):
non_ml_CHO = (0, "Low Risk")
elif (totCHO >= 140 and totCHO < 200):
non_ml_CHO = (0, "Increased Risk")
else:
non_ml_CHO = (1, "High Risk")
#blood glucose
if (glucose < 140):
non_ml_glucose = (0, "Low Risk")
elif (glucose >= 140 and glucose < 200):
non_ml_glucose = (0, "Increased Risk")
else:
non_ml_glucose = (1, "High Risk")
#bmi
if (bmi < 18.5):
non_ml_bmi = (1, "Increased Risk")
elif (bmi >= 18.5 and bmi <= 24.9):
non_ml_bmi = (0, "Low Risk")
elif (bmi >= 25 and bmi <= 29.9):
non_ml_bmi = (0, "Increased Risk")
else:
non_ml_bmi = (1, "High Risk")
#heartrate
if (restingHR < 90):
non_ml_hr = (0, "Low Risk")
elif (restingHR >= 90 and restingHR < 100):
non_ml_hr = (0, "Increased Risk")
else:
non_ml_hr = (1, "High Risk")
#smoking
if (cigs == 0):
non_ml_smoking = (0, "Low Risk")
else:
non_ml_smoking = (1, "High Risk")
#education
if (education <= 2):
non_ml_education = "Increased Risk"
else:
non_ml_education = "Low Risk"
#blood pressure
if (bpMed == 1):
non_ml_bpMed = "Increased Risk"
else:
non_ml_bpMed = "Low Risk"
#previous stroke
if (stroke == 1):
non_ml_stroke = "Increased Risk"
else:
non_ml_stroke = "Low Risk"
# return jsonify(form_data)
return render_template('results.html', results_output = ml_result,
Age = age, Sex = sex_raw , Sys_BP = sysBP,
totChol = totCHO, glucose = glucose, BMI = bmi, HR = restingHR, Smoking = cigs, Education = education_raw,
bpMed = bpMed_raw, Prev_stroke = stroke_raw,
non_ml_age = non_ml_age, non_ml_sex = non_ml_sex, non_ml_bp = non_ml_bp,
non_ml_CHO = non_ml_CHO, non_ml_glucose = non_ml_glucose, non_ml_bmi = non_ml_bmi, non_ml_HR = non_ml_hr,
non_ml_smoking = non_ml_smoking, non_ml_education = non_ml_education, non_ml_bpMed = non_ml_bpMed, non_ml_stroke = non_ml_stroke)
# return(form_data)
if __name__=="__main__":
app.run(debug=True)