alohaboy commited on
Commit
9d80233
·
1 Parent(s): 0401660

Add normal text bypass for generation - skip LLM when text is classified as normal

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -166,8 +166,21 @@ class HateSpeechDetectorService:
166
  if len(text.strip()) < 2:
167
  return "Input text is too short. Please enter at least 2 characters.", ""
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  if strategy == "Detection Only":
170
- result_msg, mitigation, debug_info = self._detection_only(text)
171
  return result_msg, mitigation
172
  elif strategy == "Guided":
173
  return self._guided_mitigation(text)
 
166
  if len(text.strip()) < 2:
167
  return "Input text is too short. Please enter at least 2 characters.", ""
168
 
169
+ # Always perform detection first
170
+ result_msg, mitigation, debug_info = self._detection_only(text)
171
+ label = debug_info.get('label', 'normal')
172
+
173
+ # If normal, bypass generation for all strategies except "Detection Only"
174
+ if label == "normal" and strategy != "Detection Only":
175
+ result_msg += f"\n\n✅ **Normal Text Detected**\n"
176
+ result_msg += f"This text is classified as normal and does not require mitigation.\n"
177
+ result_msg += f"**Original text:** {text}\n"
178
+ result_msg += f"**Mitigation:** No changes needed - text is already appropriate."
179
+ mitigation = "**Normal Text:** No mitigation required as the text is classified as normal."
180
+ return result_msg, mitigation
181
+
182
+ # For non-normal texts, proceed with the selected strategy
183
  if strategy == "Detection Only":
 
184
  return result_msg, mitigation
185
  elif strategy == "Guided":
186
  return self._guided_mitigation(text)