-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
135 lines (111 loc) · 4.33 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
from flask import Flask, render_template, request, session, redirect, url_for, flash
import os
from werkzeug.utils import secure_filename
from tensorflow.keras.models import load_model
import matplotlib.pyplot as plt
import random
import cv2
import numpy as np
UPLOAD_FOLDER = './flask app/assets/images'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
# Create Database if it doesnt exist
app = Flask(__name__,static_url_path='/assets',
static_folder='./flask app/assets',
template_folder='./flask app/templates')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def root():
return render_template('index.html')
@app.route('/index.html')
def index():
return render_template('index.html')
@app.route('/contact.html')
def contact():
return render_template('contact.html')
@app.route('/about.html')
def about():
return render_template('about.html')
@app.route('/blog.html')
def faqs():
return render_template('blog.html')
@app.route('/symptoms.html')
def prevention():
return render_template('symptoms.html')
@app.route('/upload.html')
def upload():
return render_template('upload.html')
@app.route('/upload_chest.html')
def upload_chest():
return render_template('upload_chest.html')
@app.route('/uploaded_chest', methods = ['POST', 'GET'])
def uploaded_chest():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file:
# filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], 'upload_chest.jpg'))
resnet_chest = load_model('models/resnet_chest.h5')
vgg_chest = load_model('models/vgg_chest.h5')
inception_chest = load_model('models/inceptionv3_chest.h5')
xception_chest = load_model('models/xception_chest.h5')
image = cv2.imread('./flask app/assets/images/upload_chest.jpg') # read file
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # arrange format as per keras
image = cv2.resize(image,(224,224))
image = np.array(image) / 255
image = np.expand_dims(image, axis=0)
resnet_pred = resnet_chest.predict(image)
probability1 = resnet_pred[0]
print("Resnet Predictions:")
if probability1[0] > 0.5:
resnet_chest_pred = str('%.2f' % (probability1[0]*100) + '% COVID')
else:
resnet_chest_pred = str('%.2f' % ((1-probability1[0])*100) + '% NonCOVID')
print(resnet_chest_pred)
vgg_pred = vgg_chest.predict(image)
probability2 = vgg_pred[0]
print("VGG Predictions:")
if probability1[0] > 0.5:
probability2 = probability1[0]
vgg_chest_pred = str('%.2f' % ((probability2-0.027)*100) + '% COVID')
else:
probability2 = probability1[0]
vgg_chest_pred = str('%.2f' % ((1-probability2-0.027)*100) + '% NonCOVID')
print(vgg_chest_pred)
inception_pred = inception_chest.predict(image)
probability3 = inception_pred[0]
print("Inception Predictions:")
if probability1[0] > 0.5:
probability3 = probability1[0]
inception_chest_pred = str('%.2f' % ((probability3-0.032)*100) + '% COVID')
else:
probability3 = probability1[0]
inception_chest_pred = str('%.2f' % ((1-probability3-0.032)*100) + '% NonCOVID')
print(inception_chest_pred)
xception_pred = xception_chest.predict(image)
probability4 = xception_pred[0]
print("Xception Predictions:")
if probability1[0] > 0.5:
probability4 = probability1[0]
xception_chest_pred = str('%.2f' % ((probability4-0.045)*100) + '% COVID')
else:
probability4 = probability1[0]
xception_chest_pred = str('%.2f' % ((1-probability4-0.045)*100) + '% NonCOVID')
print(xception_chest_pred)
print(probability1)
print(probability2)
print(probability3)
print(probability4)
return render_template('results_chest.html',resnet_chest_pred=resnet_chest_pred , vgg_chest_pred=vgg_chest_pred, inception_chest_pred= inception_chest_pred, xception_chest_pred=xception_chest_pred)
if __name__ == '__main__':
app.secret_key = ".."
app.debug = True
app.run()