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()