xxmaranxx commited on
Commit
420aeff
·
verified ·
1 Parent(s): 05d11c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -15,6 +15,9 @@ for k in list(centroides.keys()):
15
  centroides[k] = c / (np.linalg.norm(c) + 1e-12)
16
  cids = sorted(centroides.keys())
17
 
 
 
 
18
  # --- Clasificadores (una vez) ---
19
  sentiment = pipeline("text-classification", model="UMUTeam/roberta-spanish-sentiment-analysis")
20
  emotion = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7")
@@ -46,12 +49,21 @@ def predict(payload: dict):
46
  t = texts[i]
47
  v = embs[i]
48
  cid = _assign(v)
 
49
  s = sentiment(t)[0]["label"]
50
  e = emotion(t, candidate_labels=EMOTIONS, hypothesis_template="El texto expresa {}.")["labels"][0]
 
 
 
 
 
 
51
  results.append({
52
  "subject": data[i].get("subject",""),
53
  "body": data[i].get("body",""),
54
  "cluster": cid,
 
 
55
  "sentimiento": s,
56
  "emocion": e,
57
  })
 
15
  centroides[k] = c / (np.linalg.norm(c) + 1e-12)
16
  cids = sorted(centroides.keys())
17
 
18
+ # >>> AGREGADO: meta con nombre/descripcion por cluster (si existe en el pkl)
19
+ meta = lw.get("meta", {}) # esperado: { "0": {"nombre": "...", "descripcion": "..."}, ... }
20
+
21
  # --- Clasificadores (una vez) ---
22
  sentiment = pipeline("text-classification", model="UMUTeam/roberta-spanish-sentiment-analysis")
23
  emotion = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7")
 
49
  t = texts[i]
50
  v = embs[i]
51
  cid = _assign(v)
52
+
53
  s = sentiment(t)[0]["label"]
54
  e = emotion(t, candidate_labels=EMOTIONS, hypothesis_template="El texto expresa {}.")["labels"][0]
55
+
56
+ # >>> AGREGADO: leer nombre/descripcion del cluster desde meta (acepta clave str o int)
57
+ m = meta.get(str(cid), meta.get(cid, {}))
58
+ nombre = (m or {}).get("nombre")
59
+ desc = (m or {}).get("descripcion")
60
+
61
  results.append({
62
  "subject": data[i].get("subject",""),
63
  "body": data[i].get("body",""),
64
  "cluster": cid,
65
+ "cluster_nombre": nombre, # <<< nuevo
66
+ "cluster_desc": desc, # <<< nuevo
67
  "sentimiento": s,
68
  "emocion": e,
69
  })