-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.py
52 lines (46 loc) · 1.61 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
from flask import render_template, jsonify, Flask, redirect, url_for, request
import random
import os
import numpy as np
from keras.applications.mobilenet import MobileNet
from keras.preprocessing import image
from keras.applications.mobilenet import preprocess_input, decode_predictions
from keras.models import model_from_json
import keras
from keras import backend as K
app = Flask(__name__)
SKIN_CLASSES = {
0: 'Actinic Keratoses (Solar Keratoses) or intraepithelial Carcinoma (Bowen’s disease)',
1: 'Basal Cell Carcinoma',
2: 'Benign Keratosis',
3: 'Dermatofibroma',
4: 'Melanoma',
5: 'Melanocytic Nevi',
6: 'Vascular skin lesion'
}
@app.route('/')
def index():
return render_template('index.html', title='Home')
@app.route('/uploaded', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
path='static/data/'+f.filename
f.save(path)
j_file = open('modelnew.json', 'r')
loaded_json_model = j_file.read()
j_file.close()
model = model_from_json(loaded_json_model)
model.load_weights('modelnew.h5')
img1 = image.load_img(f, target_size=(224,224))
img1 = np.array(img1)
img1 = img1.reshape((1,224,224,3))
img1 = img1/255
prediction = model.predict(img1)
pred = np.argmax(prediction)
disease = SKIN_CLASSES[pred]
accuracy = prediction[0][pred]
K.clear_session()
return render_template('uploaded.html', title='Success', predictions=disease, acc=accuracy*100, img_file=f.filename)
if __name__ == "__main__":
app.run(debug=True)