-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
201 lines (153 loc) · 5.74 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
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
app=Flask(__name__,template_folder='template')
#app = Flask(__name__, template_folder='template')
#socketio = SocketIO(app)
# RELATED TO THE SQL DATABASE
app.config['SECRET_KEY'] = "UddA58IkCqP5nZkwEzA7YA"
#app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///site.db"
dir_path = os.path.dirname(os.path.realpath(__file__))
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")
#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
# with graph.as_default():
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
# with graph.as_default():
predicted = model2.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 = 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('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('/uploads/<filename>')
def send_file(filename):
return send_from_directory(UPLOAD_FOLDER, filename)
#Initial Home Page
@app.route("/signup")
def signup():
return render_template("signup.html")
@app.route("/")
@app.route("/login")
def login():
return render_template("login.html")
@app.route("/home")
def home():
return render_template("home.html")
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/covid_19")
def covid_19():
# if form.validate_on_submit():
return render_template("corona.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)