Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ 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',
|
|
@@ -11,20 +11,18 @@ emotion_labels = [
|
|
| 11 |
'alivio', 'remordimiento', 'tristeza', 'sorpresa', 'neutral'
|
| 12 |
]
|
| 13 |
|
| 14 |
-
# Carga del modelo desde
|
| 15 |
learn = from_pretrained_fastai("diribes/go_emotions")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# Si es una 煤nica categor铆a (clasificaci贸n simple)
|
| 27 |
-
return emotion_labels[int(pred)]
|
| 28 |
|
| 29 |
# Interfaz Gradio
|
| 30 |
iface = gr.Interface(
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import from_pretrained_fastai
|
| 4 |
|
| 5 |
+
# Lista de etiquetas de emociones en espa帽ol
|
| 6 |
emotion_labels = [
|
| 7 |
'admiraci贸n', 'diversi贸n', 'ira', 'molestia', 'aprobaci贸n', 'cuidado',
|
| 8 |
'confusi贸n', 'curiosidad', 'deseo', 'decepci贸n', 'desaprobaci贸n',
|
|
|
|
| 11 |
'alivio', 'remordimiento', 'tristeza', 'sorpresa', 'neutral'
|
| 12 |
]
|
| 13 |
|
| 14 |
+
# Carga del modelo desde Hugging Face
|
| 15 |
learn = from_pretrained_fastai("diribes/go_emotions")
|
| 16 |
|
| 17 |
+
# Clasificaci贸n con umbral personalizado
|
| 18 |
+
def clasificar_texto(texto, umbral=0.2):
|
| 19 |
+
_, _, probs = learn.predict(texto)
|
| 20 |
+
emociones_detectadas = [
|
| 21 |
+
f"{emotion_labels[i]} ({probs[i]:.2f})"
|
| 22 |
+
for i in range(len(probs))
|
| 23 |
+
if probs[i] > umbral
|
| 24 |
+
]
|
| 25 |
+
return ", ".join(emociones_detectadas) if emociones_detectadas else "Sin emoci贸n detectada"
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Interfaz Gradio
|
| 28 |
iface = gr.Interface(
|