heisenberg3376's picture
Update app.py
ca39db3 verified
raw
history blame
963 Bytes
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.input.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()