tonicanada commited on
Commit
42873f4
verified
1 Parent(s): 224f601

Uploading our food not food classifier demo from a notebook!

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -9,8 +9,16 @@ from transformers import pipeline
9
  food_not_food_classifier = pipeline(task="text-classification",
10
  model="tonicanada/learn_hf_food_not_food_text_classifier-distilbert-base-uncased",
11
  top_k=1,
 
12
  batch_size=32)
13
 
 
 
 
 
 
 
 
14
  # 3. Create a Gradio interface
15
  description = """
16
  A text classifier to determine if a sentence is about food or not food.
@@ -21,9 +29,9 @@ See [source code](https://github.com/mrdbourke/learn-huggingface/blob/main/noteb
21
  """
22
 
23
  demo = gr.Interface(
24
- 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, but it seems to have a syntax error."],
 
9
  food_not_food_classifier = pipeline(task="text-classification",
10
  model="tonicanada/learn_hf_food_not_food_text_classifier-distilbert-base-uncased",
11
  top_k=1,
12
+ device="cuda" if torch.cuda.is_available() else "cpu",
13
  batch_size=32)
14
 
15
+ def classify_text(text):
16
+ # Usa el clasificador
17
+ result = food_not_food_classifier(text)
18
+ # Devuelve la etiqueta y la puntuaci贸n
19
+ return result[0]['label'], result[0]['score']
20
+
21
+
22
  # 3. Create a Gradio interface
23
  description = """
24
  A text classifier to determine if a sentence is about food or not food.
 
29
  """
30
 
31
  demo = gr.Interface(
32
+ fn = classify_text,
33
  inputs = "text",
34
+ outputs=[gr.Label(num_top_classes=2), gr.Textbox()],
35
  title="馃崡馃毇馃 Food or Not Food Text Classifier",
36
  description=description,
37
  examples=[["I whipped up a fresh batch of code, but it seems to have a syntax error."],