Spaces:
Running
Running
File size: 1,293 Bytes
3144a67 5570bd4 3144a67 | 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 | from flask import Flask, render_template, request
import keras
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
from keras.applications.vgg16 import decode_predictions
#from keras.applications.vgg16 import VGG16
from keras.applications.resnet50 import ResNet50
app = Flask(__name__)
model = ResNet50()
@app.route('/', methods=['GET'])
def hello_word():
return render_template('index.html')
@app.route('/', methods=['POST'])
def predict():
imagefile= request.files['imagefile']
image_path = "./" + imagefile.filename
imagefile.save(image_path)
image = load_img(image_path, target_size=(224, 224))
image = img_to_array(image)
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
image = preprocess_input(image)
yhat = model.predict(image)
label = decode_predictions(yhat)
# [0][0] = (class label and probability) EX "cat, (85.00%)"
label = label[0][0]
classification = '%s (%.2f%%)' % (label[1], label[2]*100)
return render_template('index.html', prediction=classification)
if __name__ == '__main__':
app.run(port=3000, debug=True) |