SamanthaStorm commited on
Commit
341fa99
·
verified ·
1 Parent(s): 17b58e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -449,6 +449,40 @@ def generate_risk_snippet(abuse_score, top_label, escalation_score, stage):
449
  base += f"\nDetected Pattern: **{pattern_label} ({pattern_score})**\n"
450
  base += "🧠 You can review the pattern in context. This tool highlights possible dynamics—not judgments."
451
  return base
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  def compute_abuse_score(matched_scores, sentiment):
453
  if not matched_scores:
454
  return 0
@@ -714,7 +748,15 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
714
  out += "\n\n🎭 **Emotional Tones Detected:**\n"
715
  for i, tone in enumerate(tone_tags):
716
  out += f"• Message {i+1}: *{tone or 'none'}*\n"
717
-
 
 
 
 
 
 
 
 
718
  pattern_labels = [r[0][2][0][0] for r in results]
719
  timeline_image = generate_abuse_score_chart(dates_used, abuse_scores, pattern_labels)
720
  out += "\n\n" + escalation_text
 
449
  base += f"\nDetected Pattern: **{pattern_label} ({pattern_score})**\n"
450
  base += "🧠 You can review the pattern in context. This tool highlights possible dynamics—not judgments."
451
  return base
452
+
453
+ # --- Step X: Detect Immediate Danger Threats ---
454
+ THREAT_MOTIFS = [
455
+ "i'll kill you", "i’m going to hurt you", "you’re dead", "you won't survive this",
456
+ "i’ll break your face", "i'll bash your head in", "i’ll snap your neck",
457
+ "i’ll come over there and make you shut up", "i'll knock your teeth out",
458
+ "you’re going to bleed", "you want me to hit you?", "i won’t hold back next time",
459
+ "i swear to god i’ll beat you", "next time, i won’t miss", "i’ll make you scream",
460
+ "i know where you live", "i'm outside", "i’ll be waiting", "i saw you with him",
461
+ "you can’t hide from me", "i’m coming to get you", "i'll find you", "i know your schedule",
462
+ "i watched you leave", "i followed you home", "you'll regret this", "you’ll be sorry",
463
+ "you’re going to wish you hadn’t", "you brought this on yourself", "don’t push me",
464
+ "you have no idea what i’m capable of", "you better watch yourself",
465
+ "i don’t care what happens to you anymore", "i’ll make you suffer", "you’ll pay for this",
466
+ "i’ll never let you go", "you’re nothing without me", "if you leave me, i’ll kill myself",
467
+ "i'll ruin you", "i'll tell everyone what you did", "i’ll make sure everyone knows",
468
+ "i’m going to destroy your name", "you’ll lose everyone", "i’ll expose you",
469
+ "your friends will hate you", "i’ll post everything", "you’ll be cancelled",
470
+ "you’ll lose everything", "i’ll take the house", "i’ll drain your account",
471
+ "you’ll never see a dime", "you’ll be broke when i’m done", "i’ll make sure you lose your job",
472
+ "i’ll take your kids", "i’ll make sure you have nothing", "you can’t afford to leave me",
473
+ "don't make me do this", "you know what happens when i’m mad", "you’re forcing my hand",
474
+ "if you just behaved, this wouldn’t happen", "this is your fault",
475
+ "you’re making me hurt you", "i warned you", "you should have listened"
476
+ ]
477
+
478
+ # Flag any threat phrases present in the messages
479
+ def detect_threat_motifs(text, motifs):
480
+ return [m for m in motifs if m in text.lower()]
481
+
482
+ # Collect matches per message
483
+ immediate_threats = [detect_threat_motifs(m, THREAT_MOTIFS) for m, _ in active]
484
+ flat_threats = [t for sublist in immediate_threats for t in sublist]
485
+ threat_risk = "Yes" if flat_threats else "No"
486
  def compute_abuse_score(matched_scores, sentiment):
487
  if not matched_scores:
488
  return 0
 
748
  out += "\n\n🎭 **Emotional Tones Detected:**\n"
749
  for i, tone in enumerate(tone_tags):
750
  out += f"• Message {i+1}: *{tone or 'none'}*\n"
751
+ # --- Add Immediate Danger Threats section
752
+ if flat_threats:
753
+ out += "\n\n🚨 **Immediate Danger Threats Detected:**\n"
754
+ for t in set(flat_threats):
755
+ out += f"• \"{t}\"\n"
756
+ out += "\n⚠️ These phrases may indicate an imminent risk to physical safety."
757
+ else:
758
+ out += "\n\n🧩 **Immediate Danger Threats:** None explicitly detected.\n"
759
+ out += "This does *not* rule out risk, but no direct threat phrases were matched."
760
  pattern_labels = [r[0][2][0][0] for r in results]
761
  timeline_image = generate_abuse_score_chart(dates_used, abuse_scores, pattern_labels)
762
  out += "\n\n" + escalation_text