Spaces:
Build error
Build error
| import gradio as gr | |
| import numpy as np | |
| from PIL import Image | |
| import tensorflow as tf | |
| import logging | |
| #load label | |
| labels = open("labels.txt", "r") | |
| labels = labels.read().splitlines() | |
| # load model | |
| model = tf.keras.models.load_model('mobilenet_v3_large_final.h5') | |
| def predict(img): | |
| img = np.expand_dims(img, axis=0)/255 | |
| pred = model.predict(img) | |
| return {labels[i]: float(pred[0][i]) for i in range(len(labels))} | |
| title = "Shazam for Food" | |
| description = "A food classifier trained on MobileNetV3Large." | |
| article="<p style='text-align: center'><a href='https://kwangjong.github.io/https://kwangjong.github.io/2022/07/28/shazam-for-food/' target='_blank'>Blog post</a></p>" | |
| examples = ['img/waffle.jpg', "img/lasagna.jpg", "img/taco.jpg", "img/bibimbap.jpg", "img/pad-thai.jpg"] | |
| interpretation='default' | |
| enable_queue=True | |
| gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(224,224)),outputs=gr.outputs.Label(num_top_classes=5),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch() |