Spaces:
Sleeping
Sleeping
from huggingface_hub import from_pretrained_fastai | |
import gradio as gr | |
from fastai.text.all import * | |
# repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME" | |
repo_id = "allopeap/emociones" | |
learner = from_pretrained_fastai(repo_id) | |
labels = learner.dls.vocab | |
# Definimos una funci贸n que se encarga de llevar a cabo las predicciones | |
def predict(txt): | |
output = learner.predict(txt) | |
print("Output of learner.predict:", output) # Agrega esta l铆nea para depuraci贸n | |
# Desempaquetamos basado en la estructura de output | |
if len(output) == 3: | |
pred, _, probs = output | |
elif len(output) == 2: | |
pred, probs = output | |
else: | |
raise ValueError("Unexpected output format from learner.predict") | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
# Creamos la interfaz y la lanzamos. | |
gr.Interface( | |
fn=predict, | |
inputs=gr.inputs.Textbox(lines=2, placeholder="Ingresa el texto aqu铆..."), | |
outputs=gr.outputs.Label(num_top_classes=3), | |
examples=[['Me siento muy feliz hoy'], ['Estoy triste'], ['Tengo miedo']] | |
).launch(share=False) | |