heisenberg3376 commited on
Commit
f7477a5
1 Parent(s): 549c61b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the image classification pipeline from Hugging Face Transformers
5
+ pipe = pipeline("image-classification", model="heisenberg3376/vit-base-food-items-v1")
6
+
7
+ # Define the Gradio interface function
8
+ def classify_image(input_image):
9
+ # Perform classification on the input image
10
+ results = pipe(input_image)
11
+
12
+ # Prepare the output string with all predictions
13
+ output_str = "Predictions:\n"
14
+ for result in results:
15
+ output_str += f"{result['label']}: {result['score']:.4f}\n"
16
+
17
+ # Return the concatenated string of predictions
18
+ return output_str
19
+
20
+ # Create a Gradio interface
21
+ iface = gr.Interface(
22
+ fn=classify_image,
23
+ inputs=gr.inputs.Image(type="pil", label="Upload an image"),
24
+ outputs="text",
25
+ title="Image Classification",
26
+ description="Classify food items in images using heisenberg3376/vit-base-food-items-v1"
27
+ )
28
+
29
+ # Launch the Gradio interface
30
+ iface.launch()