barflyman commited on
Commit
95ce289
·
verified ·
1 Parent(s): db95a95

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from transformers import pipeline
4
+
5
+ def convert_to_rgb(image):
6
+ return image.convert('RGB')
7
+
8
+
9
+ classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
10
+
11
+
12
+ def classify_image(image):
13
+ image = convert_to_rgb(image)
14
+ class_scores = classifier(image)
15
+ highest_probability_class = max(class_scores, key=lambda x: x["score"])
16
+ highest_probability_class = highest_probability_class["label"]
17
+ return highest_probability_class, class_scores
18
+
19
+
20
+ iface = gr.Interface(fn=classify_image,
21
+ inputs=gr.Image(type="pil"),
22
+ outputs=["text", "json"],
23
+ live=True,
24
+ title="Food Image Classification",
25
+ description="Classify food items in uploaded images using a pre-trained model.")
26
+
27
+ iface.launch()