File size: 957 Bytes
f7477a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58d8b1e
b1f0a1c
f7477a5
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
from transformers import pipeline

# Load the image classification pipeline from Hugging Face Transformers
pipe = pipeline("image-classification", model="heisenberg3376/vit-base-food-items-v1")

# Define the Gradio interface function
def classify_image(input_image):
    # Perform classification on the input image
    results = pipe(input_image)
    
    # Prepare the output string with all predictions
    output_str = "Predictions:\n"
    for result in results:
        output_str += f"{result['label']}: {result['score']:.4f}\n"
    
    # Return the concatenated string of predictions
    return output_str

# Create a Gradio interface
iface = gr.Interface(
    fn=classify_image,
    input=gr.Image(type="pil", label="Upload an image"),
    output="text",
    title="Image Classification",
    description="Classify food items in images using heisenberg3376/vit-base-food-items-v1"
)

# Launch the Gradio interface
iface.launch()