Spaces:
Sleeping
Sleeping
| from fastai.learner import load_learner | |
| import gradio as gr | |
| from huggingface_hub import from_pretrained_fastai | |
| # Lista de etiquetas de emociones en espa帽ol | |
| emotion_labels = [ | |
| 'admiraci贸n', 'diversi贸n', 'ira', 'molestia', 'aprobaci贸n', 'cuidado', | |
| 'confusi贸n', 'curiosidad', 'deseo', 'decepci贸n', 'desaprobaci贸n', | |
| 'disgusto', 'verg眉enza', 'emoci贸n', 'miedo', 'gratitud', 'duelo', | |
| 'alegr铆a', 'amor', 'nerviosismo', 'optimismo', 'orgullo', 'comprensi贸n', | |
| 'alivio', 'remordimiento', 'tristeza', 'sorpresa', 'neutral' | |
| ] | |
| # Carga del modelo desde Hugging Face | |
| learn = from_pretrained_fastai("diribes/go_emotions") | |
| # Clasificaci贸n con umbral personalizado | |
| def clasificar_texto(texto, umbral=0.2): | |
| _, _, probs = learn.predict(texto) | |
| emociones_detectadas = [ | |
| f"{emotion_labels[i]} ({probs[i]:.2f})" | |
| for i in range(len(probs)) | |
| if probs[i] > umbral | |
| ] | |
| return ", ".join(emociones_detectadas) if emociones_detectadas else "Sin emoci贸n detectada" | |
| # Interfaz Gradio | |
| iface = gr.Interface( | |
| fn=clasificar_texto, | |
| inputs=gr.Textbox(lines=5, label="Introduce el texto"), | |
| outputs=gr.Label(label="Emoci贸n(es) detectada(s)"), | |
| title="Clasificador de Emociones", | |
| description="Modelo de clasificaci贸n de emociones fine-tuned con FastAI y desplegado en Hugging Face Spaces." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |