-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
255 lines (219 loc) · 8.53 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
from flask import Flask, render_template, url_for, flash, redirect
from flask import request
from flask import send_from_directory
from flask_socketio import SocketIO
import numpy as np
import tensorflow
from tensorflow import keras
import tensorflow as tf
import os
from tensorflow.keras.models import load_model
#from this import SQLAlchemy
app=Flask(__name__,template_folder='template')
app.config['SECRET_KEY'] = "UddA58IkCqP5nZkwEzA7YA"
dir_path = os.path.dirname(os.path.realpath(__file__))
# UPLOAD_FOLDER = dir_path + '/uploads'
# STATIC_FOLDER = dir_path + '/static'
UPLOAD_FOLDER = 'uploads'
STATIC_FOLDER = 'static'
#global graph
#graph = tf.get_default_graph()
model = tensorflow.keras.models.load_model('model111.h5')
model1 = tensorflow.keras.models.load_model("pneumonia.h5")
model2 = tensorflow.keras.models.load_model("Covid_model.h5")
model3 = tensorflow.keras.models.load_model("CovidCT.h5")
model4 = tensorflow.keras.models.load_model("BrainCT1.h5")
# Malaria
def api(full_path):
#with graph.as_default():
data = keras.preprocessing.image.load_img(full_path, target_size=(50, 50, 3))
data = np.expand_dims(data, axis=0)
data = data * 1.0 / 255
#with graph.as_default():
predicted = model.predict(data)
return predicted
#pneumonia
def api1(full_path):
#with graph.as_default():
data = keras.preprocessing.image.load_img(full_path, target_size=(224, 224, 3))
data = np.expand_dims(data, axis=0)
data = data * 1.0/ 255
predicted = model2.predict(data)
return predicted
#Covid-19
def api111(full_path):
#with graph.as_default():
data = keras.preprocessing.image.load_img(full_path, target_size=(224, 224, 3))
data = np.expand_dims(data, axis=0)
data = data * 1.0/ 255
predicted = model2.predict(data)
return predicted
def api1111(full_path):
#with graph.as_default():
data = keras.preprocessing.image.load_img(full_path, target_size=(224, 224, 3))
data = np.expand_dims(data, axis=0)
data = data * 1.0/ 255
predicted = model3.predict(data)
return predicted
def api2(full_path):
#with graph.as_default():
data = keras.preprocessing.image.load_img(full_path, target_size=(224, 224, 3))
data = np.expand_dims(data, axis=0)
data = data * 1.0/ 255
predicted = model4.predict(data)
return predicted
# Malaria
@app.route('/upload', methods=['POST', 'GET'])
def upload_file():
#with graph.as_default():
if request.method == 'GET':
return render_template('malaria.html')
else:
try:
file = request.files['image']
full_name = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(full_name)
indices = {0: 'PARASITIC', 1: 'Uninfected'}
result = api(full_name)
print(result)
predicted_class = np.asscalar(np.argmax(result, axis=1))
accuracy = round(result[0][predicted_class] * 100, 2)
label = indices[predicted_class]
if accuracy<85:
prediction = "Please, Check with the Doctor."
else:
prediction = "Result is accurate"
return render_template('malariapredict.html', image_file_name=file.filename, label=label, accuracy=accuracy, prediction=prediction)
except:
flash("Please select the image first !!", "danger")
return redirect(url_for("Malaria"))
#Pneumonia
@app.route('/upload11', methods=['POST', 'GET'])
def upload11_file():
#with graph.as_default():
if request.method == 'GET':
return render_template('pneumonia.html')
else:
try:
file = request.files['image']
full_name = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(full_name)
indices = {1: 'Healthy', 0: 'Pneumonia-Infected'}
result = api1(full_name)
predicted_class = np.asscalar(np.argmax(result, axis=1))
accuracy = round(result[0][predicted_class] * 100, 2)
label = indices[predicted_class]
if accuracy < 85:
prediction = "Please, Check with the Doctor."
else:
prediction = "Result is accurate"
return render_template('pneumoniapredict.html', image_file_name=file.filename, label=label, accuracy=accuracy,
prediction=prediction)
except:
flash("Please select the X-ray image first !!", "danger")
return redirect(url_for("Pneumonia"))
#Covid-19
@app.route('/upload111', methods=['POST', 'GET'])
def upload111_file():
#with graph.as_default():
if request.method == 'GET':
return render_template('corona.html')
else:
try:
file = request.files['image']
full_name = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(full_name)
indices = {1: 'Healthy', 0: 'Corona-Infected'}
result = api111(full_name)
predicted_class = np.asscalar(np.argmax(result, axis=1))
accuracy = round(result[0][predicted_class] * 100, 2)
label = indices[predicted_class]
if accuracy<85:
prediction = "Please, Check with the Doctor."
else:
prediction = "Result is accurate"
return render_template('coronapredict.html', image_file_name = file.filename, label = label, accuracy = accuracy, prediction=prediction)
except:
flash("Please select the X-ray image first !!", "danger")
return redirect(url_for("covid_19"))
@app.route('/upload1111', methods=['POST', 'GET'])
def upload1111_file():
#with graph.as_default():
if request.method == 'GET':
return render_template('corona1.html')
else:
try:
file = request.files['image']
full_name = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(full_name)
indices = {1: 'Healthy', 0: 'Corona-Infected'}
result = api1111(full_name)
predicted_class = np.asscalar(np.argmax(result, axis=1))
accuracy = round(result[0][predicted_class] * 100, 2)
label = indices[predicted_class]
if accuracy<85:
prediction = "Please, Check with the Doctor."
else:
prediction = "Result is accurate"
return render_template('coronapredict1.html', image_file_name = file.filename, label = label, accuracy = accuracy, prediction=prediction)
except:
flash("Please select the CT-Scan image first !!", "danger")
return redirect(url_for("covidct_19"))
@app.route('/upload2', methods=['POST', 'GET'])
def upload2_file():
#with graph.as_default():
if request.method == 'GET':
return render_template('brain.html')
else:
try:
file = request.files['image']
full_name = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(full_name)
indices = {1: 'Healthy', 0: 'Brain-Tumor'}
result = api1111(full_name)
predicted_class = np.asscalar(np.argmax(result, axis=1))
accuracy = round(result[0][predicted_class] * 100, 2)
label = indices[predicted_class]
if accuracy<85:
prediction = "Please, Check with the Doctor."
else:
prediction = "Result is accurate"
return render_template('brainpredict.html', image_file_name = file.filename, label = label, accuracy = accuracy, prediction=prediction)
except:
flash("Please select the CT-Scan image first !!", "danger")
return redirect(url_for("Brain"))
@app.route('/uploads/<filename>')
def send_file(filename):
return send_from_directory(UPLOAD_FOLDER, filename)
#logged in Home page
# @app.route("/login")
# def login():
# return render_template("login.html")
# @app.route("/register")
# def login1():
# return render_template("signup.html")
@app.route("/")
@app.route("/home")
def index2():
return render_template("home.html")
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/Brain")
def brain():
return render_template("brain.html")
@app.route("/covid_19")
def covid_19():
# if form.validate_on_submit():
return render_template("corona.html")
@app.route("/covidct_19")
def covidct_19():
return render_template("corona1.html")
@app.route("/Malaria")
def Malaria():
return render_template("malaria.html")
@app.route("/Pneumonia")
def Pneumonia():
return render_template("pneumonia.html")
if __name__ == "__main__":
app.run(debug=True)