File size: 835 Bytes
1f06c63
 
 
 
 
 
 
 
 
 
f8b5cfd
1f06c63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from fastai.text.all import *
from huggingface_hub import from_pretrained_fastai
import gradio as gr

learn = from_pretrained_fastai("mipedro1/emotion-classifier") 

labels = learn.dls.vocab[1]

def predict(text):
    pred, pred_idx, probs = learn.predict(text)
    return {str(labels[i]): float(probs[i]) for i in range(len(labels))}

demo = gr.Interface(
    fn=predict,
    inputs=gr.Textbox(lines=2, placeholder="text"),
    outputs=gr.Label(num_top_classes=6),
    title="Emotion Classifier",
    description="Detecta la emoción de un texto: joy, sadness, anger, fear, love o surprise.",
    examples=[
        ["I feel so happy today, everything is going great!"],
        ["I am really angry about what happened"],
        ["I'm scared about the future"],
        ["I love spending time with my family"],
    ]
)

demo.launch()