Spaces:
Running
Running
Download app.py from Mahm-oud/classifying: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/Mahm-oud/classifying/resolve/main/app.py
- Command line
-
hf download hf://spaces/Mahm-oud/classifying/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Mahm-oud/classifying/resolve/main/app.py
1.29 kB
| 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() | |
| def hello_word(): | |
| return render_template('index.html') | |
| 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) |