Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from transformers import pipeline | |
| clf = pipeline("image-classification", model="nateraw/food") # example model | |
| def predict(img): | |
| preds = clf(img) # list of {label, score} | |
| # return top 10 in format expected by gr.Label | |
| return {p["label"]: float(p["score"]) for p in preds[:10]} | |
| demo = gr.Interface(fn=predict, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="🍽️ Food detector") | |
| if __name__ == "__main__": | |
| demo.launch() | |