Spaces:
Runtime error
Runtime error
feat: uploading food caption classifier model
Browse files- README.md +11 -6
- app.py +46 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,12 +1,17 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.1.0
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Food Caption Classifier
|
| 3 |
+
emoji: π¨π±
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.1.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# π¨π± Food Caption Classifier
|
| 14 |
+
|
| 15 |
+
A text classifier model to determine whether a caption is about food or not food.
|
| 16 |
+
|
| 17 |
+
Fine-tuned from [DistilBERT](https://huggingface.co/distilbert/distilbert-base-uncased) on a [small dataset of food and not food captions](https://huggingface.co/datasets/mrdbourke/learn_hf_food_not_food_image_captions)
|
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
from typing import Dict
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def food_not_food_classifier(text: str) -> Dict[str, float]:
|
| 9 |
+
# Create the classifier pipeline
|
| 10 |
+
food_not_food_classifier_pipeline = pipeline(
|
| 11 |
+
task="text-classification",
|
| 12 |
+
model="joadithya/learn_hf_food_not_food_text_classifier-distilbert-base-uncased",
|
| 13 |
+
batch_size=32,
|
| 14 |
+
device="cuda" if torch.cuda.is_available() else "cpu",
|
| 15 |
+
top_k=None # Returning all possible labels for a given input
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# Get the outputs from the pipeline
|
| 19 |
+
outputs = food_not_food_classifier_pipeline(text)[0]
|
| 20 |
+
|
| 21 |
+
# Format output for Gradio
|
| 22 |
+
output_dict = {}
|
| 23 |
+
for item in outputs:
|
| 24 |
+
output_dict[item["label"]] = item["score"]
|
| 25 |
+
|
| 26 |
+
return output_dict
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
description = """
|
| 30 |
+
A text classifier model to determine whether a caption is about food or not food.
|
| 31 |
+
|
| 32 |
+
Fine-tuned from [DistilBERT](https://huggingface.co/distilbert/distilbert-base-uncased) on a [small dataset of food and not food captions](https://huggingface.co/datasets/mrdbourke/learn_hf_food_not_food_image_captions)
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
demo = gr.Interface(
|
| 36 |
+
inputs="text",
|
| 37 |
+
outputs=gr.Label(num_top_classes=2),
|
| 38 |
+
title="Food Caption Classifier",
|
| 39 |
+
description=description,
|
| 40 |
+
examples=[["Nothing beats the taste of home"],
|
| 41 |
+
["Love served on a plate"],
|
| 42 |
+
["A toast with cherry on top"]]
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
torch
|
| 3 |
+
transformers
|