Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -146,18 +146,17 @@ def analyze_single_message(text, thresholds):
|
|
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 |
-
|
151 |
-
|
152 |
-
|
153 |
|
154 |
-
abuse_score_raw = (weighted_total / weight_sum) * 100
|
155 |
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
abuse_score = min(abuse_score_raw, 95)
|
161 |
|
162 |
stage = get_risk_stage(threshold_labels, sentiment)
|
163 |
|
@@ -171,6 +170,7 @@ else:
|
|
171 |
print(f"Motifs: {motifs}")
|
172 |
print(f"Contradiction: {contradiction_flag}")
|
173 |
print("------------------\n")
|
|
|
174 |
return abuse_score, threshold_labels, top_patterns, result, stage
|
175 |
|
176 |
def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
@@ -200,6 +200,7 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
|
200 |
out += generate_risk_snippet(composite_abuse, top_label, escalation_score)
|
201 |
out += f"\n\n{stage_text}"
|
202 |
return out
|
|
|
203 |
textbox_inputs = [gr.Textbox(label=f"Message {i+1}") for i in range(3)]
|
204 |
quiz_boxes = [gr.Checkbox(label=q) for q, _ in ESCALATION_QUESTIONS]
|
205 |
none_box = gr.Checkbox(label="None of the above")
|
|
|
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 |
+
if "threat" in threshold_labels or "control" in threshold_labels or "insults" in threshold_labels:
|
157 |
+
abuse_score = min(abuse_score_raw, 100)
|
158 |
+
else:
|
159 |
+
abuse_score = min(abuse_score_raw, 95)
|
|
|
160 |
|
161 |
stage = get_risk_stage(threshold_labels, sentiment)
|
162 |
|
|
|
170 |
print(f"Motifs: {motifs}")
|
171 |
print(f"Contradiction: {contradiction_flag}")
|
172 |
print("------------------\n")
|
173 |
+
|
174 |
return abuse_score, threshold_labels, top_patterns, result, stage
|
175 |
|
176 |
def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
|
|
200 |
out += generate_risk_snippet(composite_abuse, top_label, escalation_score)
|
201 |
out += f"\n\n{stage_text}"
|
202 |
return out
|
203 |
+
|
204 |
textbox_inputs = [gr.Textbox(label=f"Message {i+1}") for i in range(3)]
|
205 |
quiz_boxes = [gr.Checkbox(label=q) for q, _ in ESCALATION_QUESTIONS]
|
206 |
none_box = gr.Checkbox(label="None of the above")
|