alexander1010 commited on
Commit
ee2af14
verified
1 Parent(s): d6b3396

update sentiment_analisys

Browse files
src/expon/presentation/domain/services/sentiment_analysis_service.py CHANGED
@@ -1,7 +1,6 @@
1
  import os
2
  from transformers import pipeline
3
  from typing import Dict
4
- from huggingface_hub import login
5
 
6
  # 馃憞 Redirigir el cach茅 de Hugging Face a /tmp
7
  os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers"
@@ -10,14 +9,12 @@ os.environ["HF_HOME"] = "/tmp/huggingface"
10
  class SentimentAnalysisService:
11
  def __init__(self):
12
  try:
13
- print("[LOG] Intentando iniciar sesi贸n en Hugging Face...")
14
  token = os.getenv("HUGGINGFACE_TOKEN")
15
  if not token:
16
  raise ValueError("No se encontr贸 HUGGINGFACE_TOKEN en variables de entorno")
17
- login(token)
18
- print("[LOG] Sesi贸n iniciada correctamente.")
19
  except Exception as e:
20
- print("[ERROR] Fall贸 el login:", e)
21
  raise
22
 
23
  try:
@@ -25,7 +22,8 @@ class SentimentAnalysisService:
25
  self.pipeline = pipeline(
26
  "text-classification",
27
  model="mrm8488/t5-base-spanish-emotion",
28
- top_k=1
 
29
  )
30
  print("[LOG] Pipeline cargado correctamente.")
31
  except Exception as e:
@@ -62,8 +60,7 @@ class SentimentAnalysisService:
62
  return {
63
  "dominant_emotion": mapped_emotion,
64
  "emotion_probabilities": {
65
- mapped_emotion: 1.0 # 馃憟 devolvemos 1.0 para que no tengas que tocar nada m谩s
66
  },
67
- "confidence": 1.0 # 馃憟 mismo valor fijo como antes
68
  }
69
-
 
1
  import os
2
  from transformers import pipeline
3
  from typing import Dict
 
4
 
5
  # 馃憞 Redirigir el cach茅 de Hugging Face a /tmp
6
  os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers"
 
9
  class SentimentAnalysisService:
10
  def __init__(self):
11
  try:
12
+ print("[LOG] Cargando token de Hugging Face...")
13
  token = os.getenv("HUGGINGFACE_TOKEN")
14
  if not token:
15
  raise ValueError("No se encontr贸 HUGGINGFACE_TOKEN en variables de entorno")
 
 
16
  except Exception as e:
17
+ print("[ERROR] Token inv谩lido:", e)
18
  raise
19
 
20
  try:
 
22
  self.pipeline = pipeline(
23
  "text-classification",
24
  model="mrm8488/t5-base-spanish-emotion",
25
+ top_k=1,
26
+ use_auth_token=token # 馃憟 Se usa directamente el token aqu铆
27
  )
28
  print("[LOG] Pipeline cargado correctamente.")
29
  except Exception as e:
 
60
  return {
61
  "dominant_emotion": mapped_emotion,
62
  "emotion_probabilities": {
63
+ mapped_emotion: 1.0
64
  },
65
+ "confidence": 1.0
66
  }