Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
# Crear la interfaz
|
| 21 |
-
|
| 22 |
-
inputs=gr.Textbox(label="Introduce tu texto"),
|
| 23 |
-
outputs=gr.Textbox(label="Emoci贸n detectada"),
|
| 24 |
-
title="Detector de emociones",
|
| 25 |
-
description="Introduce un texto para detectar la emoci贸n que contiene")
|
| 26 |
|
| 27 |
# Lanzar la interfaz
|
| 28 |
-
|
| 29 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Cargamos el modelo de clasificaci贸n de emociones
|
| 5 |
+
emotion_classifier = pipeline(
|
| 6 |
+
"text-classification",
|
| 7 |
+
model="finiteautomata/beto-emotion-analysis",
|
| 8 |
+
tokenizer="finiteautomata/beto-emotion-analysis",
|
| 9 |
+
return_all_scores=True
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
# Diccionario de traducci贸n de emociones en ingl茅s a espa帽ol
|
| 13 |
+
emociones_traducidas = {
|
| 14 |
+
'others': 'otras',
|
| 15 |
+
'joy': 'alegr铆a',
|
| 16 |
+
'sadness': 'tristeza',
|
| 17 |
+
'anger': 'ira',
|
| 18 |
+
'surprise': 'sorpresa',
|
| 19 |
+
'disgust': 'asco',
|
| 20 |
+
'fear': 'miedo'
|
| 21 |
+
}
|
| 22 |
|
| 23 |
+
def analizar_emocion(texto):
|
| 24 |
+
# Detectar emociones
|
| 25 |
+
resultado = emotion_classifier(texto)
|
| 26 |
+
emocion_principal = max(resultado[0], key=lambda x: x['score'])
|
| 27 |
+
etiqueta_traducida = emociones_traducidas[emocion_principal['label']]
|
| 28 |
+
return f"Emoci贸n principal: {etiqueta_traducida} (confianza: {emocion_principal['score']:.2f})"
|
| 29 |
|
| 30 |
+
# Crear la interfaz Gradio
|
| 31 |
+
iface = gr.Interface(fn=analizar_emocion, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Lanzar la interfaz
|
| 34 |
+
iface.launch()
|
|
|