-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcovid_detector.py
45 lines (28 loc) · 1.14 KB
/
covid_detector.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
from flask import *
from tensorflow.keras.models import load_model
import cv2
import numpy as np
# Creating a Python App running on Flask Server
app = Flask(__name__)
def predictCOVID(imageToBeTested):
model = load_model("covid_initial.h5")
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
image = cv2.imread(imageToBeTested)
image = cv2.resize(image, (300, 300))
image = np.reshape(image, [1, 300, 300, 3])
classes = model.predict_classes(image) # [[0]]
label = ["COVID-19 INFECTED", "NORMAL"]
return label[classes[0][0]]
@app.route('/')
def index():
return render_template("predict.html")
@app.route('/upload-image', methods=['POST'])
def uploadImage():
if request.method == 'POST': # Just to Validate if user is uploading the file in POST Request
file = request.files['image']
file.save(file.filename)
label = predictCOVID(file.filename)
return render_template('result.html', name=label)
if __name__ == '__main__':
# app.run() # execute the app i.e. let the app run on Flask Server
app.run(debug=True) # Enable Debugging for the error