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