Bodhisattva-Duduka's picture
Update app.py
059e86a verified
raw
history blame contribute delete
856 Bytes
import gradio as gr
from transformers import pipeline
try:
classifier = pipeline("image-classification", model="prithivMLmods/Recycling-Net-11")
except Exception as e:
print("🚨 Error loading model:", e)
classifier = None
def classify_image(image):
if classifier is None:
return {"error": "Model failed to load"}
try:
results = classifier(image)
return {r["label"]: float(r["score"]) for r in results}
except Exception as e:
print("🚨 Error during classification:", e)
return {"error": str(e)}
demo = gr.Interface(
fn=classify_image,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
title="♻️ Recycling Classifier",
description="Upload an image of waste material and the model will classify it."
)
if __name__ == "__main__":
demo.launch()