Spaces:
Sleeping
Sleeping
update new
Browse files
src/expon/presentation/domain/services/sentiment_analysis_service.py
CHANGED
@@ -1,18 +1,17 @@
|
|
1 |
-
import os
|
2 |
from transformers import pipeline
|
|
|
3 |
from typing import Dict
|
4 |
|
5 |
-
# 👇 Redirigir el caché de Hugging Face a /tmp para compatibilidad en Hugging Face Spaces
|
6 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers"
|
7 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
8 |
|
9 |
class SentimentAnalysisService:
|
10 |
def __init__(self):
|
11 |
try:
|
12 |
-
print("[LOG] Cargando pipeline con modelo
|
13 |
self.pipeline = pipeline(
|
14 |
-
"
|
15 |
-
model="
|
16 |
top_k=1
|
17 |
)
|
18 |
print("[LOG] Pipeline cargado correctamente.")
|
@@ -25,7 +24,7 @@ class SentimentAnalysisService:
|
|
25 |
try:
|
26 |
result = self.pipeline(transcript)[0]
|
27 |
print("[LOG] Resultado del modelo:", result)
|
28 |
-
label = result['label'].
|
29 |
score = result['score']
|
30 |
except Exception as e:
|
31 |
print("[ERROR] Falló la predicción:", e)
|
@@ -35,13 +34,10 @@ class SentimentAnalysisService:
|
|
35 |
"confidence": 0.0
|
36 |
}
|
37 |
|
38 |
-
# Mapeo muy simple de estrellas a emociones (puedes personalizar esto más)
|
39 |
emotion_mapping = {
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"4 stars": "motivado",
|
44 |
-
"5 stars": "entusiasta"
|
45 |
}
|
46 |
|
47 |
mapped_emotion = emotion_mapping.get(label, "desconocido")
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
+
import os
|
3 |
from typing import Dict
|
4 |
|
|
|
5 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers"
|
6 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
7 |
|
8 |
class SentimentAnalysisService:
|
9 |
def __init__(self):
|
10 |
try:
|
11 |
+
print("[LOG] Cargando pipeline con modelo BETO...")
|
12 |
self.pipeline = pipeline(
|
13 |
+
"sentiment-analysis",
|
14 |
+
model="finiteautomata/beto-sentiment-analysis",
|
15 |
top_k=1
|
16 |
)
|
17 |
print("[LOG] Pipeline cargado correctamente.")
|
|
|
24 |
try:
|
25 |
result = self.pipeline(transcript)[0]
|
26 |
print("[LOG] Resultado del modelo:", result)
|
27 |
+
label = result['label'].upper()
|
28 |
score = result['score']
|
29 |
except Exception as e:
|
30 |
print("[ERROR] Falló la predicción:", e)
|
|
|
34 |
"confidence": 0.0
|
35 |
}
|
36 |
|
|
|
37 |
emotion_mapping = {
|
38 |
+
"POS": "entusiasta",
|
39 |
+
"NEU": "neutro",
|
40 |
+
"NEG": "frustrado"
|
|
|
|
|
41 |
}
|
42 |
|
43 |
mapped_emotion = emotion_mapping.get(label, "desconocido")
|