File size: 540 Bytes
d9e596c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import gradio as gr
from transformers import pipeline
MODEL_ID = "nateraw/food" # <- replace with any model above
clf = pipeline("image-classification", model=MODEL_ID)
def predict(img):
out = clf(img)
# show top-3 with scores
out = sorted(out, key=lambda r: r["score"], reverse=True)[:3]
return {r["label"]: float(r["score"]) for r in out}
gr.Interface(
fn=predict,
inputs=gr.Image(type="pil", label="Upload image"),
outputs=gr.Label(num_top_classes=3),
title="Image Classifier (pre-tuned)",
).launch()
|