SamanthaStorm commited on
Commit
b90535a
·
verified ·
1 Parent(s): 055c725

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -529,8 +529,18 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
529
  escalation_text = f"🧨 **Escalation Potential: {risk_level} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})**\n"
530
  escalation_text += "This score comes directly from the safety checklist and functions as a standalone escalation risk score.\n"
531
  escalation_text += "It indicates how many serious risk factors are present based on your answers to the safety checklist.\n"
532
- if top_label is None:
533
- top_label = "Unknown – 0%"
 
 
 
 
 
 
 
 
 
 
534
  out += generate_risk_snippet(composite_abuse, top_label, escalation_score if escalation_score is not None else 0, most_common_stage)
535
  out += f"\n\n{stage_text}"
536
  out += darvo_blurb
 
529
  escalation_text = f"🧨 **Escalation Potential: {risk_level} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})**\n"
530
  escalation_text += "This score comes directly from the safety checklist and functions as a standalone escalation risk score.\n"
531
  escalation_text += "It indicates how many serious risk factors are present based on your answers to the safety checklist.\n"
532
+ # Derive top_label from the strongest top_patterns across all messages
533
+ top_label = None
534
+ if results:
535
+ sorted_patterns = sorted(
536
+ [(label, score) for r in results for label, score in r[0][2]],
537
+ key=lambda x: x[1],
538
+ reverse=True
539
+ )
540
+ if sorted_patterns:
541
+ top_label = f"{sorted_patterns[0][0]} – {int(round(sorted_patterns[0][1] * 100))}%"
542
+ if top_label is None:
543
+ top_label = "Unknown – 0%"
544
  out += generate_risk_snippet(composite_abuse, top_label, escalation_score if escalation_score is not None else 0, most_common_stage)
545
  out += f"\n\n{stage_text}"
546
  out += darvo_blurb