-
Notifications
You must be signed in to change notification settings - Fork 64
/
app.py
113 lines (96 loc) · 3.95 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
from flask import Flask, render_template, request, flash, redirect
import pickle
import numpy as np
from PIL import Image
from tensorflow.keras.models import load_model
app = Flask(__name__)
def predict(values, dic):
if len(values) == 8:
model = pickle.load(open('models/diabetes.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
elif len(values) == 26:
model = pickle.load(open('models/breast_cancer.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
elif len(values) == 13:
model = pickle.load(open('models/heart.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
elif len(values) == 18:
model = pickle.load(open('models/kidney.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
elif len(values) == 10:
model = pickle.load(open('models/liver.pkl','rb'))
values = np.asarray(values)
return model.predict(values.reshape(1, -1))[0]
@app.route("/")
def home():
return render_template('home.html')
@app.route("/diabetes", methods=['GET', 'POST'])
def diabetesPage():
return render_template('diabetes.html')
@app.route("/cancer", methods=['GET', 'POST'])
def cancerPage():
return render_template('breast_cancer.html')
@app.route("/heart", methods=['GET', 'POST'])
def heartPage():
return render_template('heart.html')
@app.route("/kidney", methods=['GET', 'POST'])
def kidneyPage():
return render_template('kidney.html')
@app.route("/liver", methods=['GET', 'POST'])
def liverPage():
return render_template('liver.html')
@app.route("/malaria", methods=['GET', 'POST'])
def malariaPage():
return render_template('malaria.html')
@app.route("/pneumonia", methods=['GET', 'POST'])
def pneumoniaPage():
return render_template('pneumonia.html')
@app.route("/predict", methods = ['POST', 'GET'])
def predictPage():
try:
if request.method == 'POST':
to_predict_dict = request.form.to_dict()
to_predict_list = list(map(float, list(to_predict_dict.values())))
pred = predict(to_predict_list, to_predict_dict)
except:
message = "Please enter valid Data"
return render_template("home.html", message = message)
return render_template('predict.html', pred = pred)
@app.route("/malariapredict", methods = ['POST', 'GET'])
def malariapredictPage():
if request.method == 'POST':
try:
if 'image' in request.files:
img = Image.open(request.files['image'])
img = img.resize((36,36))
img = np.asarray(img)
img = img.reshape((1,36,36,3))
img = img.astype(np.float64)
model = load_model("models/malaria.h5")
pred = np.argmax(model.predict(img)[0])
except:
message = "Please upload an Image"
return render_template('malaria.html', message = message)
return render_template('malaria_predict.html', pred = pred)
@app.route("/pneumoniapredict", methods = ['POST', 'GET'])
def pneumoniapredictPage():
if request.method == 'POST':
try:
if 'image' in request.files:
img = Image.open(request.files['image']).convert('L')
img = img.resize((36,36))
img = np.asarray(img)
img = img.reshape((1,36,36,1))
img = img / 255.0
model = load_model("models/pneumonia.h5")
pred = np.argmax(model.predict(img)[0])
except:
message = "Please upload an Image"
return render_template('pneumonia.html', message = message)
return render_template('pneumonia_predict.html', pred = pred)
if __name__ == '__main__':
app.run(debug = True)