Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -143,8 +143,21 @@ def analyze_single_message(text, thresholds):
|
|
143 |
reverse=True
|
144 |
)[:2]
|
145 |
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
stage = get_risk_stage(threshold_labels, sentiment)
|
150 |
|
|
|
143 |
reverse=True
|
144 |
)[:2]
|
145 |
|
146 |
+
# Compute weighted average across all patterns (not just top 2)
|
147 |
+
weighted_total = 0.0
|
148 |
+
weight_sum = 0.0
|
149 |
+
for label, score in zip(LABELS, scores):
|
150 |
+
weight = PATTERN_WEIGHTS.get(label, 1.0)
|
151 |
+
weighted_total += score * weight
|
152 |
+
weight_sum += weight
|
153 |
+
|
154 |
+
abuse_score_raw = (weighted_total / weight_sum) * 100
|
155 |
+
|
156 |
+
# Cap abuse intensity at 100 only if high-threat patterns are present
|
157 |
+
if "threat" in threshold_labels or "control" in threshold_labels or "insults" in threshold_labels:
|
158 |
+
abuse_score = min(abuse_score_raw, 100)
|
159 |
+
else:
|
160 |
+
abuse_score = min(abuse_score_raw, 95)
|
161 |
|
162 |
stage = get_risk_stage(threshold_labels, sentiment)
|
163 |
|