-
Notifications
You must be signed in to change notification settings - Fork 24
/
app.py
362 lines (268 loc) · 11.5 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
from flask import Flask, request, render_template
import pickle, os
import numpy as np
import pandas as pd
from flask_pymongo import PyMongo
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.imagenet_utils import preprocess_input, decode_predictions
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'medicare-prime'
app.config['MONGO_URI'] = 'mongodb+srv://admin:[email protected]/medicare-prime?retryWrites=true&w=majority'
mongo = PyMongo(app)
def model_predictKidney(values):
model = pickle.load(open('models/kidney/kidney.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
def model_predictCovid(values):
model = pickle.load(open('models/covid/covid.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
def model_predictDiabetes(values):
model = pickle.load(open('models/diabetes/diabetes.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
def model_predictDengue(values):
model = pickle.load(open('models/dengue/Dengue.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
def model_predictParkinsonDisease(values):
model = pickle.load(open('models/ParkinsonDisease/parkinson.pickle','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
def model_predictThyroidDisease(values):
model = pickle.load(open('models/ThyroidDisease/thyroid.pickle','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
def model_predictMalaria(img_path):
model = load_model('models/malaria/malaria.h5')
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x=x/255
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
preds=np.argmax(preds, axis=1)
print(preds)
return preds
def model_predictBreastCancer(df):
model1 = pickle.load(open('models/breastCancer/model1.pickle','rb'))
return model1.predict(df)[0]
def model_predictHeartDisease(df):
model = pickle.load(open('models/heartDisease/model.pickle','rb'))
return model.predict(df)[0]
def login():
master = mongo.db.Users
b = str(request.form.get("password_input", False))
result = master.find_one({"Password":b})
if result is not None:
if b==result['Password']:
return 1
return 0
@app.route("/")
def home():
return render_template('index.html')
@app.route("/departments", methods=['GET', 'POST'])
def departments():
return render_template('departments.html')
@app.route("/kidney", methods=['GET', 'POST'])
def kidney():
return render_template('kidney.html')
@app.route("/covid", methods=['GET', 'POST'])
def covid():
return render_template('covid.htm')
@app.route("/dengue", methods=['GET', 'POST'])
def dengue():
return render_template('dengue.html')
@app.route("/ParkinsonDisease", methods=['GET', 'POST'])
def ParkinsonDisease():
return render_template('parkinsonDisease.html')
@app.route("/ThyroidDisease", methods=['GET', 'POST'])
def ThyroidDisease():
return render_template('thyroidDisease.html')
@app.route("/malaria", methods=['GET', 'POST'])
def malaria():
return render_template('malaria.html')
@app.route("/diabetes", methods=['GET', 'POST'])
def diabetes():
return render_template('diabetes.html')
@app.route("/breastCancer", methods=['GET', 'POST'])
def breastCancer():
return render_template('breastCancer.html')
@app.route("/heartDisease", methods=['GET', 'POST'])
def heartDisease():
return render_template('heartDisease.html')
@app.route("/login", methods=['GET', 'POST'])
def loginPage():
return render_template('login.html')
@app.route("/userDashboard", methods=['GET', 'POST'])
def checkLogin():
flag = login()
if flag == 0:
return render_template('login.html', text="Invalid Credential")
else:
return render_template('shady.html')
@app.route("/signup", methods=['GET', 'POST'])
def signup():
master = mongo.db.Users
a = str(request.form.get("name_input", False))
b = str(request.form.get("password_input", False))
post = {'Username': a, 'Password' : b}
master.insert_one(post)
return render_template('signup.html')
@app.route("/predictKidney", methods = ['POST', 'GET'])
def predictKidney():
try:
if request.method == 'POST':
to_predict_dict = request.form.to_dict()
to_predict_list = list(map(float, list(to_predict_dict.values())))
pred = model_predictKidney(to_predict_list)
except:
message = "Please enter valid Data"
return render_template("index_content.html", message = message)
if pred == 1:
res_val = "Patient is suffering from Kidney disease"
else:
res_val = "Patient is not suffering from Kidney disease"
master = mongo.db.predictKidney;
master.insert({'Test Report': res_val})
return render_template('predictKidney.html', pred = pred)
@app.route("/predictCovid", methods = ['POST', 'GET'])
def predictCovid():
try:
if request.method == 'POST':
to_predict_dict = request.form.to_dict()
to_predict_list = list(map(float, list(to_predict_dict.values())))
pred = model_predictKidney(to_predict_list)
except:
message = "Please enter valid Data"
return render_template("index_content.html", message = message)
if pred == 1:
res_val = "Patient is suffering from Covid"
else:
res_val = "Patient is not suffering from Covid"
master = mongo.db.predictCovid;
master.insert({'Test Report': res_val})
return render_template('predictCovid.html', pred = pred)
@app.route("/predictDiabetes", methods = ['POST', 'GET'])
def predictDiabetes():
try:
if request.method == 'POST':
to_predict_dict = request.form.to_dict()
to_predict_list = list(map(float, list(to_predict_dict.values())))
pred = model_predictDiabetes(to_predict_list)
except:
message = "Please enter valid Data"
return render_template("index_content.html", message = message)
if pred == 1:
res_val = "Patient is suffering from Diabetes"
else:
res_val = "Patient is not suffering from Diabetes"
master = mongo.db.predictDiabetes;
master.insert({'Test Report': res_val})
return render_template('predictDiabetes.html', pred = pred)
@app.route("/predictDengue", methods = ['POST', 'GET'])
def predictDengue():
try:
if request.method == 'POST':
to_predict_dict = request.form.to_dict()
to_predict_list = list(map(float, list(to_predict_dict.values())))
pred = model_predictDengue(to_predict_list)
except:
message = "Please enter valid Data"
return render_template("index_content.html", message = message)
if pred == 1:
res_val = "Patient is suffering from Dengue"
else:
res_val = "Patient is not suffering from Dengue"
master = mongo.db.predictDiabetes;
master.insert({'Test Report': res_val})
return render_template('predictDengue.html', pred = pred)
@app.route('/predictParkinsonDisease',methods=['POST', 'GET'])
def predictParkinson():
try:
if request.method == 'POST':
to_predict_dict = request.form.to_dict()
to_predict_list = list(map(float, list(to_predict_dict.values())))
pred = model_predictParkinsonDisease(to_predict_list)
except:
message = "Please enter valid Data"
return render_template("index_content.html", message = message)
if pred == 1:
res_val = "Patient is suffering from Parkinson Disease"
else:
res_val = "Patient is not suffering from Parkinson Disease"
master = mongo.db.predictDiabetes;
master.insert({'Test Report': res_val})
return render_template('predictParkinson.html', pred = pred)
@app.route('/predictThyroidDisease',methods=['POST', 'GET'])
def predictThyroid():
try:
if request.method == 'POST':
to_predict_dict = request.form.to_dict()
to_predict_list = list(map(float, list(to_predict_dict.values())))
pred = model_predictParkinsonDisease(to_predict_list)
except:
message = "Please enter valid Data"
return render_template("index_content.html", message = message)
if pred == 1:
res_val = "Patient is suffering from Thyroid Disease"
else:
res_val = "Patient is not suffering from Thyroid Disease"
master = mongo.db.predictDiabetes;
master.insert({'Test Report': res_val})
return render_template('predictThyroid.html', pred = pred)
@app.route("/predictMalaria", methods = ['POST', 'GET'])
def predictMalaria():
output = "Invalid request method"
if request.method == 'POST':
# Get the file from post request
f = request.files['file']
basepath = os.path.dirname(__file__)
file_path = os.path.join(
basepath, 'static/uploads', secure_filename(f.filename))
f.save(file_path)
# Make prediction
preds = model_predictMalaria(file_path)
class_names = ["The Person is Infected With Malaria.","The Person is not Infected With Malaria."]
output = class_names[preds[0]]
return render_template('predictMalaria.html', pred = output)
@app.route('/predictBreastCancer',methods=['POST'])
def predictBreastCancer():
input_features = [float(x) for x in request.form.values()]
features_value = [np.array(input_features)]
features_name = ['mean radius', 'mean texture', 'mean perimeter', 'mean area',
'mean smoothness', 'mean compactness', 'mean concavity',
'mean concave points', 'mean symmetry', 'mean fractal dimension',
'radius error', 'texture error', 'perimeter error', 'area error',
'smoothness error', 'compactness error', 'concavity error',
'concave points error', 'symmetry error', 'fractal dimension error',
'worst radius', 'worst texture', 'worst perimeter', 'worst area',
'worst smoothness', 'worst compactness', 'worst concavity',
'worst concave points', 'worst symmetry', 'worst fractal dimension']
df = pd.DataFrame(features_value, columns=features_name)
output = model_predictBreastCancer(df)
if output[0] == 'M':
res_val = "breast cancer "
else:
res_val = "no breast cancer"
master = mongo.db.predictBreastCancer;
master.insert({'Test Report': res_val})
return render_template('breastCancer.html', prediction_text='Patient has {}'.format(res_val))
@app.route('/predictHeartDisease',methods=['POST'])
def predict():
input_features = [float(x) for x in request.form.values()]
features_value = [np.array(input_features)]
features_name = ['cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach', 'exang', 'oldpeak', 'slope', 'ca', 'thal']
df = pd.DataFrame(features_value, columns=features_name)
output = model_predictHeartDisease(df)
if output == 1:
res_val = "Heart Disease"
else:
res_val = "no Heart Disease."
master = mongo.db.predictHeartDisease;
master.insert_one({'Test Report': res_val})
return render_template('heartDisease.html', prediction_text='Patient has {}'.format(res_val))
if __name__ == '__main__':
app.run(debug=True)