Spaces:
Runtime error
Runtime error
import gradio as gr | |
import tensorflow as tf | |
from tensorflow import keras | |
import huggingface_hub | |
from huggingface_hub import from_pretrained_keras | |
# load custom pre-trained model from HuggingFace models | |
model_api_link = 'chaninder/waste-sorting-model' | |
pre_trained_model = from_pretrained_keras(model_api_link) | |
# classification labels | |
labels = ['compost', 'e-waste', 'recycle', 'trash'] | |
def classify_image(input): | |
prediction = pre_trained_model.predict(input) | |
confidences = {labels[i]: float(prediction[i]) for i in range(4)} | |
return confidences | |
# create Gradio interface | |
iface = gr.Interface(fn=classify_image, | |
inputs=gr.Image(shape=(224, 224)), | |
outputs=gr.Label(num_top_classes=4), | |
#examples=["banana.jpg", "car.jpg"] | |
) | |
iface.launch(share=True) |