Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
|
|
4 |
pipe = pipeline(
|
5 |
"image-classification",
|
6 |
model="ariG23498/vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101"
|
7 |
)
|
8 |
|
|
|
9 |
def classify(image):
|
10 |
return pipe(image)[0]["label"]
|
11 |
|
12 |
-
|
13 |
-
demo.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize the pipeline
|
5 |
pipe = pipeline(
|
6 |
"image-classification",
|
7 |
model="ariG23498/vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101"
|
8 |
)
|
9 |
|
10 |
+
# Function for classification
|
11 |
def classify(image):
|
12 |
return pipe(image)[0]["label"]
|
13 |
|
14 |
+
# Gradio Interface with a detailed description
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=classify,
|
17 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
18 |
+
outputs=gr.Textbox(label="Predicted Label"),
|
19 |
+
examples=[["./sushi.png", "sushi"]],
|
20 |
+
title="Food Classification with ViT 🥗🍣",
|
21 |
+
description=(
|
22 |
+
"### Explore Food Classification with Vision Transformers (ViT) 🔍\n\n"
|
23 |
+
"This application demonstrates the power of Vision Transformers (ViT) for food classification tasks, "
|
24 |
+
"leveraging the pre-trained model `vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101` fine-tuned on the Food-101 dataset. "
|
25 |
+
"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"
|
26 |
+
"#### How to Use:\n"
|
27 |
+
"1. Upload an image of food (e.g., sushi, pizza, or burgers).\n"
|
28 |
+
"2. The model will classify the image and provide the predicted label.\n"
|
29 |
+
"3. Try the provided example for a quick start or test your own food images!\n\n"
|
30 |
+
"#### About the Model:\n"
|
31 |
+
"- **Model Name**: `vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101`\n"
|
32 |
+
"- **Dataset**: [Food-101](https://www.kaggle.com/dansbecker/food-101)\n"
|
33 |
+
"- **Architecture**: Vision Transformers (ViT), which process images by splitting them into patches and leveraging self-attention for feature extraction.\n\n"
|
34 |
+
"#### Learn More:\n"
|
35 |
+
"Discover more about Vision Transformers in the [Hugging Face blog](https://huggingface.co/blog). "
|
36 |
+
"Explore the Food-101 dataset [here](https://www.kaggle.com/dansbecker/food-101)."
|
37 |
+
)
|
38 |
+
)
|
39 |
+
|
40 |
+
demo.launch()
|