Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,29 +37,30 @@ class ModelHandler:
|
|
| 37 |
except Exception as e:
|
| 38 |
return f"Error al realizar la inferencia: {e}"
|
| 39 |
|
| 40 |
-
def analyze_emotion(input_text):
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
try:
|
| 52 |
-
client = InferenceClient("bhadresh-savani/distilbert-base-uncased-emotion", token=hf_token)
|
| 53 |
-
response = client.text_classification(input_text)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Lista de modelos disponibles (con nombres amigables para la interfaz)
|
| 64 |
model_names = {
|
| 65 |
"CHATBOT": "microsoft/Phi-3-mini-4k-instruct"
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
return f"Error al realizar la inferencia: {e}"
|
| 39 |
|
| 40 |
+
def analyze_emotion(self, input_text):
|
| 41 |
+
# Diccionario para traducir emociones al espa帽ol
|
| 42 |
+
emotion_translation = {
|
| 43 |
+
"joy": "Alegr铆a",
|
| 44 |
+
"anger": "Enojo",
|
| 45 |
+
"fear": "Miedo",
|
| 46 |
+
"sadness": "Tristeza",
|
| 47 |
+
"love": "Amor",
|
| 48 |
+
"surprise": "Sorpresa"
|
| 49 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
try:
|
| 52 |
+
client = InferenceClient("bhadresh-savani/distilbert-base-uncased-emotion", token=hf_token)
|
| 53 |
+
response = client.text_classification(input_text)
|
| 54 |
+
|
| 55 |
+
# Traducir las emociones y formatear la respuesta
|
| 56 |
+
emotions = [
|
| 57 |
+
f"{emotion_translation[label['label']]}: {label['score']:.2%}"
|
| 58 |
+
for label in response
|
| 59 |
+
]
|
| 60 |
+
return "\n".join(emotions)
|
| 61 |
+
except Exception as e:
|
| 62 |
+
return f"Error al analizar la emoci贸n: {e}"
|
| 63 |
+
|
| 64 |
# Lista de modelos disponibles (con nombres amigables para la interfaz)
|
| 65 |
model_names = {
|
| 66 |
"CHATBOT": "microsoft/Phi-3-mini-4k-instruct"
|