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