Khriis commited on
Commit
1b95ed9
·
verified ·
1 Parent(s): d0a5cbd

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +16 -17
handler.py CHANGED
@@ -161,25 +161,24 @@ class EndpointHandler:
161
  "RECCON raw spans (answer, score): %s",
162
  [(p.get("answer"), p.get("score", 0.0), 3) for p in current_preds[:5]]
163
  )
164
-
165
- best_score = max((p.get("score", 0.0) for p in current_preds), default=0.0)
166
-
167
- MIN_BEST_SCORE = 0.01 # start here; tune later
168
- if best_score < MIN_BEST_SCORE:
169
- results.append({
170
- "utterance": utterance,
171
- "emotion": emotion,
172
- "triggers": [], # no highlight
173
- "metadata": {"low_confidence": True, "best_score": best_score}
174
- })
175
- pred_idx += 1
176
- continue
177
 
178
- # Extract the answer strings
179
- raw_answers = [p.get('answer', '') for p in current_preds]
 
 
 
 
 
 
 
 
 
 
 
180
 
181
- # Clean spans using your original logic
182
- triggers = self._clean_spans(raw_answers, utterance)
 
183
 
184
  results.append({
185
  "utterance": utterance,
 
161
  "RECCON raw spans (answer, score): %s",
162
  [(p.get("answer"), p.get("score", 0.0), 3) for p in current_preds[:5]]
163
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
+ def is_good_span(ans: str) -> bool:
166
+ if not ans:
167
+ return False
168
+ a = ans.strip()
169
+ if len(a) < 3:
170
+ return False
171
+ # reject pure punctuation
172
+ if all(ch in ".,!?;:-—'\"()[]{}" for ch in a):
173
+ return False
174
+ # require at least one letter
175
+ if not any(ch.isalpha() for ch in a):
176
+ return False
177
+ return True
178
 
179
+ raw_answers = [p.get("answer", "") for p in current_preds]
180
+ raw_answers = [a for a in raw_answers if is_good_span(a)]
181
+ triggers = self._clean_spans(raw_answers, utterance)
182
 
183
  results.append({
184
  "utterance": utterance,