Katon1 commited on
Commit
f86b41c
verified
1 Parent(s): 25a5b01

cambio de analisis de emogi

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -37,16 +37,29 @@ class ModelHandler:
37
  except Exception as e:
38
  return f"Error al realizar la inferencia: {e}"
39
 
40
- def analyze_emotion(self, input_text):
41
- # Analiza la emoci贸n del texto proporcionado
42
- try:
43
- client = InferenceClient("bhadresh-savani/distilbert-base-uncased-emotion", token=hf_token)
44
- response = client.text_classification(input_text)
45
- emotions = [f"{label['label']}: {label['score']:.2f}" for label in response]
46
- return "\n".join(emotions)
47
- except Exception as e:
48
- return f"Error al analizar la emoci贸n: {e}"
49
-
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  # Lista de modelos disponibles (con nombres amigables para la interfaz)
51
  model_names = {
52
  "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(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
  # Lista de modelos disponibles (con nombres amigables para la interfaz)
64
  model_names = {
65
  "CHATBOT": "microsoft/Phi-3-mini-4k-instruct"