Unizomby commited on
Commit
215797d
β€’
1 Parent(s): 84acbb7

Uploading food not food text classifier demo app.py

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +7 -7
README.md CHANGED
@@ -13,5 +13,5 @@ license: apache-2.0
13
 
14
  Small demo to showcase a text classifier to determine if a sentence is about food or not food. Enter a sentence in the box below.
15
 
16
- DistillBERT model fine-tuned on a small synthetic dataset of 250 generated [Food or Not Food image captions](https://huggingface.co/datasets/mrdbourke/learn_hf_food_not_food_image_captions).
17
 
 
13
 
14
  Small demo to showcase a text classifier to determine if a sentence is about food or not food. Enter a sentence in the box below.
15
 
16
+ DistillBERT model fine-tuned on a small synthetic dataset of 250 generated [Food or Not Food image captions](https://huggingface.co/datasets/Unizomby/food_not_food_image_captions).
17
 
app.py CHANGED
@@ -5,15 +5,15 @@ import gradio as gr
5
  from typing import Dict
6
  from transformers import pipeline
7
 
8
- # 2. Define function to use our model on given text
9
  def food_not_food_classifier(text: str) -> Dict[str, float]:
10
  # Set up text classification pipeline
11
- food_not_food_classifier = pipeline(task="text-classification",
12
  # Because our model is on Hugging Face already, we can pass in the model name directly
13
  model="Unizomby/food_not_food_text_classifier-distilbert-base-uncased", # link to model on HF Hub
14
  device="cuda" if torch.cuda.is_available() else "cpu",
15
  top_k=None) # return all possible scores (not just top-1)
16
-
17
  # Get outputs from pipeline (as a list of dicts)
18
  outputs = food_not_food_classifier(text)[0]
19
 
@@ -26,13 +26,13 @@ def food_not_food_classifier(text: str) -> Dict[str, float]:
26
 
27
  # 3. Create a Gradio interface with details about our app
28
  description = """
29
- A text classifier to determine if a sentence is about food or not food.
30
 
31
- Fine-tuned from [DistilBERT](https://huggingface.co/distilbert/distilbert-base-uncased) on a [small dataset of food and not food text](https://huggingface.co/datasets/mrdbourke/learn_hf_food_not_food_image_captions).
32
  """
33
 
34
- demo = gr.Interface(fn=food_not_food_classifier,
35
- inputs="text",
36
  outputs=gr.Label(num_top_classes=2), # show top 2 classes (that's all we have)
37
  title="Food or Not Food Text Classifier πŸ•πŸ«",
38
  description=description,
 
5
  from typing import Dict
6
  from transformers import pipeline
7
 
8
+ # 2. Define function to use our model on given text
9
  def food_not_food_classifier(text: str) -> Dict[str, float]:
10
  # Set up text classification pipeline
11
+ food_not_food_classifier = pipeline(task="text-classification",
12
  # Because our model is on Hugging Face already, we can pass in the model name directly
13
  model="Unizomby/food_not_food_text_classifier-distilbert-base-uncased", # link to model on HF Hub
14
  device="cuda" if torch.cuda.is_available() else "cpu",
15
  top_k=None) # return all possible scores (not just top-1)
16
+
17
  # Get outputs from pipeline (as a list of dicts)
18
  outputs = food_not_food_classifier(text)[0]
19
 
 
26
 
27
  # 3. Create a Gradio interface with details about our app
28
  description = """
29
+ A text classifier to determine if a sentence is about food or not food.
30
 
31
+ Fine-tuned from [DistilBERT](https://huggingface.co/distilbert/distilbert-base-uncased) on a [small dataset of food and not food text](https://huggingface.co/datasets/Unizomby/food_not_food_image_captions).
32
  """
33
 
34
+ demo = gr.Interface(fn=food_not_food_classifier,
35
+ inputs="text",
36
  outputs=gr.Label(num_top_classes=2), # show top 2 classes (that's all we have)
37
  title="Food or Not Food Text Classifier πŸ•πŸ«",
38
  description=description,