vu0018 commited on
Commit
4a839d5
·
verified ·
1 Parent(s): d043368

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ clf = pipeline("image-classification", model="nateraw/food") # example model
6
+
7
+ def predict(img):
8
+ preds = clf(img) # list of {label, score}
9
+ # return top 3 in format expected by gr.Label
10
+ return {p["label"]: float(p["score"]) for p in preds[:3]}
11
+
12
+ demo = gr.Interface(fn=predict,
13
+ inputs=gr.Image(type="pil"),
14
+ outputs=gr.Label(num_top_classes=3),
15
+ title="🍽️ Food detector")
16
+ if __name__ == "__main__":
17
+ demo.launch()