Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,30 @@
|
|
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 |
-
|
|
|
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.
|
19 |
examples=[["./sushi.png", "sushi"]],
|
20 |
title="Food Classification with ViT π₯π£",
|
21 |
description=(
|
22 |
-
"
|
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 |
-
"
|
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
|
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 |
|
|
|
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 |
+
results = pipe(image)
|
11 |
+
return {result["label"]: round(result["score"], 2) for result in results}
|
12 |
|
|
|
13 |
demo = gr.Interface(
|
14 |
fn=classify,
|
15 |
inputs=gr.Image(type="pil", label="Upload an Image"),
|
16 |
+
outputs=gr.Label(num_top_classes=3, label="Top Predictions"),
|
17 |
examples=[["./sushi.png", "sushi"]],
|
18 |
title="Food Classification with ViT π₯π£",
|
19 |
description=(
|
20 |
+
"# Explore Food Classification with Vision Transformers (ViT) π\n\n"
|
21 |
"This application demonstrates the power of Vision Transformers (ViT) for food classification tasks, "
|
22 |
"leveraging the pre-trained model `vit_base_patch16_224.augreg2_in21k_ft_in1k.ft_food101` fine-tuned on the Food-101 dataset. "
|
23 |
"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"
|
24 |
+
"## How to Use:\n"
|
25 |
"1. Upload an image of food (e.g., sushi, pizza, or burgers).\n"
|
26 |
+
"2. The model will classify the image and provide the predicted labels along with confidence scores.\n"
|
27 |
"3. Try the provided example for a quick start or test your own food images!\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
)
|
29 |
)
|
30 |
|