SamanthaStorm commited on
Commit
700db29
·
verified ·
1 Parent(s): 1345886

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -143,8 +143,21 @@ def analyze_single_message(text, thresholds):
143
  reverse=True
144
  )[:2]
145
 
146
- weighted_scores = [(PATTERN_WEIGHTS.get(label, 1.0) * score) for label, score in top_patterns]
147
- abuse_score = min(np.mean(weighted_scores) * 100, 100)
 
 
 
 
 
 
 
 
 
 
 
 
 
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