-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
33 lines (27 loc) · 983 Bytes
/
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
import flask
from flask import Flask, render_template, request
import numpy as np
from tensorflow.keras.models import load_model
import imageio
app = Flask(__name__)
@app.route('/')
def index():
return flask.render_template('index.html')
@app.route('/predict', methods=['POST'])
def make_prediction():
if request.method == 'POST':
file = request.files['image']
if not file:
return render_template('index.html', label="No file")
img = imageio.imread(file)
img_arr = np.array(img)
img_size = 150
img_arr = np.resize(img_arr, (img_size, img_size, img_arr.shape[2]))
img_arr = np.array([img_arr])
classifier = load_model('model.h5')
prediction = np.argmax(classifier.predict(img_arr), axis=1)
label = int(prediction[0])
print(label)
return render_template('index.html', label=label)
if __name__ == '__main__':
app.run(debug=True)