Spaces:
Sleeping
Sleeping
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, | |
inputs=gr.inputs.Image(type="pil", label="Upload an image"), | |
outputs="text", | |
title="Image Classification", | |
description="Classify food items in images using heisenberg3376/vit-base-food-items-v1" | |
) | |
# Launch the Gradio interface | |
iface.launch() | |