Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -265,8 +265,19 @@ def analyze_single_message(text, thresholds):
|
|
265 |
weighted_total += score * weight
|
266 |
weight_sum += weight
|
267 |
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
if weapon_flag:
|
271 |
abuse_score_raw = min(abuse_score_raw + 25, 100) # boost intensity
|
272 |
if weapon_flag and stage < 2:
|
@@ -318,7 +329,7 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
|
|
318 |
|
319 |
results = [(analyze_single_message(m, THRESHOLDS.copy()), d) for m, d in active]
|
320 |
abuse_scores = [r[0][0] for r in results]
|
321 |
-
top_labels = [r[0][2][0][0] for r in results]
|
322 |
top_scores = [r[0][2][0][1] for r in results]
|
323 |
sentiments = [r[0][3]['label'] for r in results]
|
324 |
stages = [r[0][4] for r in results]
|
|
|
265 |
weighted_total += score * weight
|
266 |
weight_sum += weight
|
267 |
|
268 |
+
matched_scores = [
|
269 |
+
(label, score, PATTERN_WEIGHTS.get(label, 1.0))
|
270 |
+
for label, score in zip(LABELS, scores)
|
271 |
+
if score > adjusted_thresholds[label]
|
272 |
+
]
|
273 |
+
|
274 |
+
if matched_scores:
|
275 |
+
weighted_total = sum(score * weight for _, score, weight in matched_scores)
|
276 |
+
weight_sum = sum(weight for _, _, weight in matched_scores)
|
277 |
+
abuse_score_raw = (weighted_total / weight_sum) * 100
|
278 |
+
else:
|
279 |
+
abuse_score_raw = 0
|
280 |
+
stage = get_risk_stage(threshold_labels, sentiment)
|
281 |
if weapon_flag:
|
282 |
abuse_score_raw = min(abuse_score_raw + 25, 100) # boost intensity
|
283 |
if weapon_flag and stage < 2:
|
|
|
329 |
|
330 |
results = [(analyze_single_message(m, THRESHOLDS.copy()), d) for m, d in active]
|
331 |
abuse_scores = [r[0][0] for r in results]
|
332 |
+
top_labels = [r[0][1][0] if r[0][1] else r[0][2][0][0] for r in results]
|
333 |
top_scores = [r[0][2][0][1] for r in results]
|
334 |
sentiments = [r[0][3]['label'] for r in results]
|
335 |
stages = [r[0][4] for r in results]
|