SamanthaStorm commited on
Commit
91451af
Β·
verified Β·
1 Parent(s): 408ccbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -16
app.py CHANGED
@@ -133,7 +133,7 @@ def get_risk_stage(patterns, sentiment):
133
  return 4
134
  return 1
135
 
136
- def generate_risk_snippet(abuse_score, top_label, escalation_score, stage=None):
137
  if abuse_score >= 85 or escalation_score >= 16:
138
  risk_level = "high"
139
  elif abuse_score >= 60 or escalation_score >= 8:
@@ -246,7 +246,7 @@ def analyze_single_message(text, thresholds):
246
  def analyze_composite(msg1, msg2, msg3, *answers_and_none):
247
  responses = answers_and_none[:len(ESCALATION_QUESTIONS)]
248
  none_selected = answers_and_none[-1]
249
- escalation_score = None if none_selected else sum(w for (_, w), a in zip(ESCALATION_QUESTIONS, responses) if a)
250
  messages = [msg1, msg2, msg3]
251
  active = [m for m in messages if m.strip()]
252
  if not active:
@@ -260,27 +260,36 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
260
  stages = [r[4] for r in results]
261
  darvo_scores = [r[5] for r in results]
262
 
 
 
 
263
  most_common_stage = max(set(stages), key=stages.count)
264
  stage_text = RISK_STAGE_LABELS[most_common_stage]
 
265
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
266
- top_label = f"{top_labels[0]} – {int(round(top_scores[0] * 100))}%"
267
- composite_abuse = int(round(sum(abuse_scores) / len(abuse_scores)))
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
  out = f"Abuse Intensity: {composite_abuse}%\n"
270
  out += "πŸ“Š This reflects the strength and severity of detected abuse patterns in the message(s).\n\n"
271
- if escalation_score is None:
272
- out += "Escalation Potential: Unknown (Checklist not completed)\n"
273
- out += "πŸ” *This section was not completed. Escalation potential is unknown.*\n\n"
274
- else:
275
- out += f"Escalation Potential: {('High' if escalation_score >= 16 else 'Moderate' if escalation_score >= 8 else 'Low')} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})\n"
276
- out += "🚨 This indicates how many serious risk factors are present based on your answers to the safety checklist.\n\n"
277
- out += generate_risk_snippet(composite_abuse, top_label, escalation_score, most_common_stage)
278
  out += f"\n\n{stage_text}"
279
-
280
- avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
281
- if avg_darvo > 0.25:
282
- level = "moderate" if avg_darvo < 0.65 else "high"
283
- out += f"\n\n🎭 **DARVO Score: {avg_darvo}** β†’ This indicates a **{level} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
284
 
285
  return out
286
 
 
133
  return 4
134
  return 1
135
 
136
+ def generate_risk_snippet(abuse_score, top_label, escalation_score, stage):
137
  if abuse_score >= 85 or escalation_score >= 16:
138
  risk_level = "high"
139
  elif abuse_score >= 60 or escalation_score >= 8:
 
246
  def analyze_composite(msg1, msg2, msg3, *answers_and_none):
247
  responses = answers_and_none[:len(ESCALATION_QUESTIONS)]
248
  none_selected = answers_and_none[-1]
249
+
250
  messages = [msg1, msg2, msg3]
251
  active = [m for m in messages if m.strip()]
252
  if not active:
 
260
  stages = [r[4] for r in results]
261
  darvo_scores = [r[5] for r in results]
262
 
263
+ composite_abuse = int(round(sum(abuse_scores) / len(abuse_scores)))
264
+ top_label = f"{top_labels[0]} – {int(round(top_scores[0] * 100))}%"
265
+
266
  most_common_stage = max(set(stages), key=stages.count)
267
  stage_text = RISK_STAGE_LABELS[most_common_stage]
268
+
269
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
270
+ darvo_blurb = ""
271
+ if avg_darvo > 0.25:
272
+ level = "moderate" if avg_darvo < 0.65 else "high"
273
+ darvo_blurb = f"\n\n🎭 **DARVO Score: {avg_darvo}** β†’ This indicates a **{level} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
274
+
275
+ if none_selected:
276
+ escalation_score = 0
277
+ escalation_potential = "Unknown (Checklist not completed)"
278
+ escalation_note = "πŸ” *This section was not completed. Escalation potential is unknown.*"
279
+ else:
280
+ escalation_score = sum(w for (_, w), a in zip(ESCALATION_QUESTIONS, responses) if a)
281
+ escalation_total = sum(w for _, w in ESCALATION_QUESTIONS)
282
+ level = "High" if escalation_score >= 16 else "Moderate" if escalation_score >= 8 else "Low"
283
+ escalation_potential = f"{level} ({escalation_score}/{escalation_total})"
284
+ escalation_note = "🚨 This indicates how many serious risk factors are present based on your answers to the safety checklist."
285
 
286
  out = f"Abuse Intensity: {composite_abuse}%\n"
287
  out += "πŸ“Š This reflects the strength and severity of detected abuse patterns in the message(s).\n\n"
288
+ out += f"Escalation Potential: {escalation_potential}\n"
289
+ out += f"{escalation_note}\n\n"
290
+ out += generate_risk_snippet(composite_abuse, top_label, escalation_score)
 
 
 
 
291
  out += f"\n\n{stage_text}"
292
+ out += darvo_blurb
 
 
 
 
293
 
294
  return out
295