| |
| """app.ipynb |
| |
| Automatically generated by Colaboratory. |
| |
| Original file is located at |
| https://colab.research.google.com/drive/1JBeFqVg174Vi6bnvIEGFNqvWFuNZlgxC |
| """ |
|
|
| import gradio as gr |
| import numpy as np |
| import tensorflow_hub as hub |
| from tensorflow.keras.models import load_model |
| import cv2 |
|
|
| |
| custom_objects = {'KerasLayer': hub.KerasLayer} |
|
|
| |
| model = load_model('model.h5', custom_objects=custom_objects) |
|
|
| |
| class_label = [] |
|
|
| |
| with open('label.txt', 'r') as file: |
| class_label = [line.strip() for line in file.read().splitlines()] |
|
|
|
|
| def predict_image(image): |
| img = cv2.resize(image, (224, 224)) |
| img = img / 255.0 |
| predictions = model.predict(img[np.newaxis, ...])[0] |
| top_classes = np.argsort(predictions)[-3:][::-1] |
| top_class = top_classes[0] |
| label = class_label[top_class] |
| return label |
|
|
|
|
| |
| input_image = gr.inputs.Image(shape=(224, 224)) |
| output_label = gr.outputs.Label() |
|
|
| gr.Interface(fn=predict_image, inputs=input_image, outputs=output_label, capture_session=True).launch() |