-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
44 lines (34 loc) · 1.25 KB
/
main.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
import os
import numpy as np
import Model
from werkzeug.utils import secure_filename
from flask import Flask, render_template, request
UPLOAD_FOLDER = './static\\model_data\\'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
model = Model.MyModel()
def DeleteTemporaryFiles():
files = os.scandir('./static/model_data')
for file in files:
if file.is_file():
os.remove(file)
@app.route("/")
def hello():
return render_template('index.html')
@app.route('/predict', methods=["GET", "POST"])
def predict():
if request.method == "POST":
DeleteTemporaryFiles()
file = request.files['image']
fileName = os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(file.filename))
file.save(fileName)
(name, prob) = model.predict(fileName)
print(name, prob)
if name == 'NORMAL':
prob = f'The probabilty of having no Pneumonia is {str(1-prob)[:5]}%'
elif name == 'PNEUMONIA':
prob = f'The probabilty of having Pneumonia is {str(prob)[:5]}%'
return render_template("results.html", predicted_name=name, probability=prob, url=fileName)
return render_template('index.html')
app.run(debug=True)