Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -121,7 +121,15 @@ def analyze_messages(input_text, risk_flags):
|
|
121 |
scored_patterns = [
|
122 |
(label, score) for label, score in zip(PATTERN_LABELS, scores[:15]) if label != "non_abusive"
|
123 |
]
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
top_pattern_explanations = "\n".join([
|
127 |
f"• {label.replace('_', ' ').title()}: {EXPLANATIONS.get(label, 'No explanation available.')}"
|
|
|
121 |
scored_patterns = [
|
122 |
(label, score) for label, score in zip(PATTERN_LABELS, scores[:15]) if label != "non_abusive"
|
123 |
]
|
124 |
+
# Override top patterns if a high-risk motif was detected
|
125 |
+
override_labels = {"physical_threat", "suicidal_threat", "extreme_control"}
|
126 |
+
override_matches = [label for label, _ in matched_phrases if label in override_labels]
|
127 |
+
|
128 |
+
if override_matches:
|
129 |
+
top_patterns = [(label, 1.0) for label in override_matches]
|
130 |
+
else:
|
131 |
+
top_patterns = sorted(scored_patterns, key=lambda x: x[1], reverse=True)[:2]
|
132 |
+
top_patterns = sorted(scored_patterns, key=lambda x: x[1], reverse=True)[:2]
|
133 |
|
134 |
top_pattern_explanations = "\n".join([
|
135 |
f"• {label.replace('_', ' ').title()}: {EXPLANATIONS.get(label, 'No explanation available.')}"
|