SamanthaStorm commited on
Commit
57b9f91
Β·
verified Β·
1 Parent(s): dee6092

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -247,7 +247,11 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
247
  none_selected_checked = answers_and_none[-1]
248
  responses_checked = any(answers_and_none[:-1])
249
  none_selected = not responses_checked and none_selected_checked
250
-
 
 
 
 
251
  messages = [msg1, msg2, msg3]
252
  active = [m for m in messages if m.strip()]
253
  if not active:
@@ -263,7 +267,6 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
263
 
264
  composite_abuse = int(round(sum(abuse_scores) / len(abuse_scores)))
265
  top_label = f"{top_labels[0]} – {int(round(top_scores[0] * 100))}%"
266
-
267
  most_common_stage = max(set(stages), key=stages.count)
268
  stage_text = RISK_STAGE_LABELS[most_common_stage]
269
 
@@ -275,12 +278,11 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
275
 
276
  out = f"Abuse Intensity: {composite_abuse}%\n"
277
  out += "πŸ“Š This reflects the strength and severity of detected abuse patterns in the message(s).\n\n"
278
- out += f"Escalation Potential: {risk_level} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})\n"
279
- out += "🚨 This indicates how many serious risk factors are present based on your answers to the safety checklist.\n\n"
280
  if escalation_score is None:
281
  out += "Escalation Potential: Unknown (Checklist not completed)\n"
282
  out += "πŸ” *This section was not completed. Escalation potential is unknown.*\n\n"
283
- risk_level = "unknown" # just in case something tries to reference it later
284
  else:
285
  risk_level = (
286
  "High" if escalation_score >= 16 else
@@ -289,7 +291,7 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
289
  )
290
  out += f"Escalation Potential: {risk_level} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})\n"
291
  out += "🚨 This indicates how many serious risk factors are present based on your answers to the safety checklist.\n\n"
292
- )
293
  out += generate_risk_snippet(composite_abuse, top_label, escalation_score, most_common_stage)
294
  out += f"\n\n{stage_text}"
295
  out += darvo_blurb
 
247
  none_selected_checked = answers_and_none[-1]
248
  responses_checked = any(answers_and_none[:-1])
249
  none_selected = not responses_checked and none_selected_checked
250
+
251
+ escalation_score = None if none_selected else sum(
252
+ w for (response, (q, w)) in zip(answers_and_none[:-1], ESCALATION_QUESTIONS) if response
253
+ )
254
+
255
  messages = [msg1, msg2, msg3]
256
  active = [m for m in messages if m.strip()]
257
  if not active:
 
267
 
268
  composite_abuse = int(round(sum(abuse_scores) / len(abuse_scores)))
269
  top_label = f"{top_labels[0]} – {int(round(top_scores[0] * 100))}%"
 
270
  most_common_stage = max(set(stages), key=stages.count)
271
  stage_text = RISK_STAGE_LABELS[most_common_stage]
272
 
 
278
 
279
  out = f"Abuse Intensity: {composite_abuse}%\n"
280
  out += "πŸ“Š This reflects the strength and severity of detected abuse patterns in the message(s).\n\n"
281
+
 
282
  if escalation_score is None:
283
  out += "Escalation Potential: Unknown (Checklist not completed)\n"
284
  out += "πŸ” *This section was not completed. Escalation potential is unknown.*\n\n"
285
+ escalation_score = 0 # fallback to allow generate_risk_snippet to still work
286
  else:
287
  risk_level = (
288
  "High" if escalation_score >= 16 else
 
291
  )
292
  out += f"Escalation Potential: {risk_level} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})\n"
293
  out += "🚨 This indicates how many serious risk factors are present based on your answers to the safety checklist.\n\n"
294
+
295
  out += generate_risk_snippet(composite_abuse, top_label, escalation_score, most_common_stage)
296
  out += f"\n\n{stage_text}"
297
  out += darvo_blurb