Spaces:
Sleeping
Sleeping
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]
|
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]
|
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
|
66 |
},
|
67 |
-
"confidence": 1.0
|
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 |
}
|
|