Spaces:
Running
Running
File size: 1,964 Bytes
599cf8a 33a2adb 599cf8a b455d78 599cf8a 33a2adb 599cf8a 33a2adb |
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 32 33 34 35 36 37 38 39 40 41 |
import gradio as gr
from transformers import pipeline
# Initialize the pipeline
pipe = pipeline(
"image-classification",
model="ariG23498/vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101"
)
# Function for classification
def classify(image):
return pipe(image)[0]["label"]
# Gradio Interface with a detailed description
demo = gr.Interface(
fn=classify,
inputs=gr.Image(type="pil", label="Upload an Image"),
outputs=gr.Textbox(label="Predicted Label"),
examples=[["./sushi.png", "sushi"]],
title="Food Classification with ViT π₯π£",
description=(
"### Explore Food Classification with Vision Transformers (ViT) π\n\n"
"This application demonstrates the power of Vision Transformers (ViT) for food classification tasks, "
"leveraging the pre-trained model `vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101` fine-tuned on the Food-101 dataset. "
"With just a few lines of code, you can integrate state-of-the-art image classification models using the Hugging Face `pipeline` API.\n\n"
"#### How to Use:\n"
"1. Upload an image of food (e.g., sushi, pizza, or burgers).\n"
"2. The model will classify the image and provide the predicted label.\n"
"3. Try the provided example for a quick start or test your own food images!\n\n"
"#### About the Model:\n"
"- **Model Name**: `vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101`\n"
"- **Dataset**: [Food-101](https://www.kaggle.com/dansbecker/food-101)\n"
"- **Architecture**: Vision Transformers (ViT), which process images by splitting them into patches and leveraging self-attention for feature extraction.\n\n"
"#### Learn More:\n"
"Discover more about Vision Transformers in the [Hugging Face blog](https://huggingface.co/blog). "
"Explore the Food-101 dataset [here](https://www.kaggle.com/dansbecker/food-101)."
)
)
demo.launch()
|