Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.learner import load_learner
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from huggingface_hub import from_pretrained_fastai
|
| 4 |
+
|
| 5 |
+
# Lista de etiquetas de emociones
|
| 6 |
+
emotion_labels = [
|
| 7 |
+
'admiraci贸n', 'diversi贸n', 'ira', 'molestia', 'aprobaci贸n', 'cuidado',
|
| 8 |
+
'confusi贸n', 'curiosidad', 'deseo', 'decepci贸n', 'desaprobaci贸n',
|
| 9 |
+
'disgusto', 'verg眉enza', 'emoci贸n', 'miedo', 'gratitud', 'duelo',
|
| 10 |
+
'alegr铆a', 'amor', 'nerviosismo', 'optimismo', 'orgullo', 'comprensi贸n',
|
| 11 |
+
'alivio', 'remordimiento', 'tristeza', 'sorpresa', 'neutral'
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
# Carga del modelo desde HuggingFace Hub
|
| 15 |
+
learn = from_pretrained_fastai("diribes/go_emotions")
|
| 16 |
+
|
| 17 |
+
# Funci贸n de predicci贸n
|
| 18 |
+
def clasificar_texto(texto):
|
| 19 |
+
pred, idxs, probs = learn.predict(texto)
|
| 20 |
+
|
| 21 |
+
# Si el modelo es multietiqueta (lista de 铆ndices)
|
| 22 |
+
if isinstance(pred, list):
|
| 23 |
+
pred_labels = [emotion_labels[int(i)] for i in pred]
|
| 24 |
+
return ", ".join(pred_labels)
|
| 25 |
+
|
| 26 |
+
# Si es una sola etiqueta
|
| 27 |
+
return emotion_labels[int(pred)]
|
| 28 |
+
|
| 29 |
+
# Interfaz Gradio
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=clasificar_texto,
|
| 32 |
+
inputs=gr.Textbox(lines=5, label="Introduce el texto"),
|
| 33 |
+
outputs=gr.Label(label="Emoci贸n(es) detectada(s)"),
|
| 34 |
+
title="Clasificador de Emociones",
|
| 35 |
+
description="Modelo de clasificaci贸n de emociones fine-tuned con FastAI y desplegado en Hugging Face Spaces."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
iface.launch()
|