Spaces:
Sleeping
Sleeping
File size: 928 Bytes
7c728e6 e603649 7c728e6 a24da99 7c728e6 f104126 4f5448e 7c728e6 27ed3da 7c728e6 e603649 ae8196c 7c728e6 4d30ff5 e603649 2e69908 |
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 |
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/trashtacks-model-final'
pre_trained_model = from_pretrained_keras(model_api_link)
# classification labels
labels = ['compost', 'e-waste', 'recycle', 'trash']
def classify_image(inp):
inp = inp.reshape((-1, 224, 224, 3))
#inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
prediction = pre_trained_model.predict(inp).flatten()
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", 'can.jpg'])
iface.launch() |