Spaces:
Sleeping
Sleeping
Download app.py from Doja2002/image-classifier-one: direct link, hf CLI and curl.
- Browser
- Download file 540 Bytes
-
https://huggingface.co/spaces/Doja2002/image-classifier-one/resolve/main/app.py
- Command line
-
hf download hf://spaces/Doja2002/image-classifier-one/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Doja2002/image-classifier-one/resolve/main/app.py
540 Bytes
| 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() | |