Uploading food not food text classifier demo app.py
Browse files- README.md +4 -7
- app.py +33 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,12 +1,9 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
|
5 |
-
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.1.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Food Not Food Classifier
|
3 |
+
colorFrom: blue
|
4 |
+
colorTo: yellow
|
|
|
5 |
sdk: gradio
|
|
|
6 |
app_file: app.py
|
7 |
pinned: false
|
8 |
+
license: apache-2.0
|
9 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
from typing import Dict
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
def food_not_food_classifier(text: str) -> Dict[str, float]:
|
9 |
+
food_not_food_classifier = pipeline(task="text-classification",
|
10 |
+
model="tanvircr7/learn_hf_food_not_food_text_classifier-distilbert-base-uncased",
|
11 |
+
device="cuda" if torch.cuda.is_available() else "cpu",
|
12 |
+
top_k=None)
|
13 |
+
outputs = food_not_food_classifier(text)[0]
|
14 |
+
output_dict = {}
|
15 |
+
for item in outputs:
|
16 |
+
output_dict[item["label"]] = item["score"]
|
17 |
+
return output_dict
|
18 |
+
|
19 |
+
description = """
|
20 |
+
A text classifier to determine if a sentence is about food or not food.
|
21 |
+
Fine-tuned from DistilBERT
|
22 |
+
"""
|
23 |
+
|
24 |
+
demo = gr.Interface(fn=food_not_food_classifier,
|
25 |
+
inputs="text",
|
26 |
+
outputs=gr.Label(num_top_classes=2),
|
27 |
+
title="Food or Not Food Text Classifier",
|
28 |
+
description=description,
|
29 |
+
examples=[["I whipped up a fresh batch of code"],["A delicious photo of a plate"]]
|
30 |
+
)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
transformers
|