Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import from_pretrained_fastai
|
2 |
+
import gradio as gr
|
3 |
+
from fastai.vision.all import *
|
4 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
5 |
+
import torch
|
6 |
+
|
7 |
+
|
8 |
+
# repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
|
9 |
+
repo_id = "islasher/clasificador-dair-emotion"
|
10 |
+
|
11 |
+
learner = from_pretrained_fastai(repo_id)
|
12 |
+
labels = learner.dls.vocab
|
13 |
+
|
14 |
+
# Definimos una función que se encarga de llevar a cabo las predicciones
|
15 |
+
|
16 |
+
|
17 |
+
# Cargar el modelo y el tokenizador
|
18 |
+
nombre_modelo = "clasificador-dair-emotion"
|
19 |
+
model = AutoModelForSequenceClassification.from_pretrained(nombre_modelo)
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(nombre_modelo)
|
21 |
+
|
22 |
+
|
23 |
+
def predict(frase):
|
24 |
+
#img = PILImage.create(img)
|
25 |
+
inputs = tokenizer(frase, return_tensors="pt")
|
26 |
+
outputs = model(**inputs)
|
27 |
+
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
28 |
+
return predicted_class
|
29 |
+
|
30 |
+
# Creamos la interfaz y la lanzamos.
|
31 |
+
gr.Interface(fn=predict, inputs="text", outputs=gr.outputs.Label(num_top_classes=6)).launch(share=False)
|
32 |
+
|