tonicanada
commited on
Commit
•
8c66ef7
1
Parent(s):
9194493
Uploading our food not food classifier demo from a notebook!
Browse files- README.md +10 -6
- app.py +34 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.5.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Clasificador de asignaturas
|
3 |
+
emoji: 📚🔍
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: yellow
|
6 |
sdk: gradio
|
|
|
7 |
app_file: app.py
|
8 |
pinned: false
|
9 |
+
license: apache-2.0
|
10 |
---
|
11 |
|
12 |
+
# 📚🔍 Clasificador de asignaturas
|
13 |
+
|
14 |
+
Pequeña demo que clasifica las frases según si se refieren a asignaturas escolares (ejemplo: matemáticas, religión, etc).
|
15 |
+
|
16 |
+
DistillBERT model fine-tuned on a small synthetic dataset of 250 generated [Frases ejemplo](https://huggingface.co/datasets/tonicanada/learn_hf_spanish_sentence_classification_by_school_subject).
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 1. Import the required libraries
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
from typing import Dict
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
# 2. Define our function to use with our model
|
9 |
+
spanish_sentence_classification_by_school_subject_pipeline = pipeline(task="text-classification",
|
10 |
+
model="tonicanada/learn_hf_spanish_sentence_classification_by_school_subject",
|
11 |
+
top_k=1,
|
12 |
+
device="cuda" if torch.cuda.is_available() else "cpu",
|
13 |
+
batch_size=32)
|
14 |
+
|
15 |
+
# 3. Create a Gradio interface
|
16 |
+
description = """
|
17 |
+
Un clasificador de texto que indica a qué asignatura se refiere la frase.
|
18 |
+
|
19 |
+
Fine-tuned from [DistilBERT](https://huggingface.co/distilbert/distilbert/distilbert-base-multilingual-cased) on a [small dataset of food and not food text](https://huggingface.co/datasets/mrdbourke/learn_hf_food_not_food_image_captions).
|
20 |
+
"""
|
21 |
+
|
22 |
+
demo = gr.Interface(
|
23 |
+
fn = spanish_sentence_classification_by_school_subject_pipeline,
|
24 |
+
inputs = "text",
|
25 |
+
outputs=gr.Label(num_top_classes=10),
|
26 |
+
title="📚🔍 Clasificador de asignaturas",
|
27 |
+
description=description,
|
28 |
+
examples=[["Matemáticas: 5 al cuadrado es 25"],
|
29 |
+
["Geografía: París es la capital de Francia"]])
|
30 |
+
|
31 |
+
|
32 |
+
# 4. Launch the interface
|
33 |
+
if __name__ == "__main__":
|
34 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
transformers
|