-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
66 lines (56 loc) · 2.05 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
import base64
import json
from io import BytesIO
import numpy as np
import requests
from flask import Flask, request, jsonify, render_template, redirect, flash, url_for
import tensorflow as tf
from tensorflow import keras
import functools
from scipy import ndimage, misc
from PIL import Image
from keras.models import load_model
model = load_model('model.h5')
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'medhacks/img'
categories = ['Actinic Keratoses',
'Basal Cell Carcinoma',
'Benign Keratosis',
'Dermatofibroma',
'Melanoma',
'Melanocytic Nevi',
'Vascular skin lesion']
preds = np.zeros(7)
@app.route("/")
def index():
return render_template('fileupload2.html')
@app.route("/doctor", methods=['GET', 'POST'])
def doctor():
return render_template('doctor.html')
@app.route("/fileupload", methods=['GET', 'POST'])
def fileupload():
if request.method == "POST":
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file:
image = np.asarray(Image.open(request.files["image"]).stream.resize((100,75)))
image.shape = (1,) + image.shape
preds = model.predict(image)[0]
print("DEBUG: IMAGE RECEIVED")
print(preds)
return redirect(url_for('results'))
return render_template("fileupload2.html")
@app.route("/results", methods=['GET'])
def results():
zipped = zip(categories, preds)
sorted_pred = sorted(zipped, reverse = True)
pred_str = [(str(p[0]) + ': ' + str(p[1])) for p in sorted_pred]
# pred_str = ['Actinic Keratoses: 0.0', 'Basal Cell Carcinoma: 0.0', 'Benign Keratosis: 0.0', 'Dermatofibroma: 0.0', 'Melanoma: 1.0', 'Melanocytic Nevi: 0.0', 'Vascular skin lesion: 0.0']
return render_template('results.html', pred = pred_str)
if __name__ == '__main__':
app.run(debug=True)