hrlima commited on
Commit
b91b466
·
verified ·
1 Parent(s): 43c32a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -95,18 +95,22 @@ def analyze():
95
  text = data["text"]
96
  print(f"\n🧠 Texto recebido: {text}\n")
97
 
98
- # Se modelo local não está carregado → fallback
99
  if not emotion_pipeline:
100
  print("⚠️ Modelo não carregado. Usando fallback.")
101
  return jsonify(fallback_emotion(text))
102
 
103
- # Faz análise com modelo local
104
  result = emotion_pipeline(text)
 
 
 
 
 
105
  if not result or not isinstance(result, list):
106
  print("⚠️ Resultado inesperado. Usando fallback.")
107
  return jsonify(fallback_emotion(text))
108
 
109
- # Processar resultados
110
  scores = {r['label'].lower(): float(r['score']) for r in result}
111
  emotion = max(scores, key=scores.get)
112
  confidence = round(scores[emotion], 3)
 
95
  text = data["text"]
96
  print(f"\n🧠 Texto recebido: {text}\n")
97
 
 
98
  if not emotion_pipeline:
99
  print("⚠️ Modelo não carregado. Usando fallback.")
100
  return jsonify(fallback_emotion(text))
101
 
102
+ # Faz a predição
103
  result = emotion_pipeline(text)
104
+
105
+ # 🔧 Corrige formato: pipeline retorna [[{...}, {...}, ...]]
106
+ if isinstance(result, list) and isinstance(result[0], list):
107
+ result = result[0]
108
+
109
  if not result or not isinstance(result, list):
110
  print("⚠️ Resultado inesperado. Usando fallback.")
111
  return jsonify(fallback_emotion(text))
112
 
113
+ # Extrai as probabilidades
114
  scores = {r['label'].lower(): float(r['score']) for r in result}
115
  emotion = max(scores, key=scores.get)
116
  confidence = round(scores[emotion], 3)