Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -643,9 +643,20 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
|
|
643 |
active = [(m, d) for m, d in zip(messages, dates) if m.strip()]
|
644 |
if not active:
|
645 |
return "Please enter at least one message."
|
|
|
646 |
# Flag any threat phrases present in the messages
|
647 |
-
|
648 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
649 |
|
650 |
# Collect matches per message
|
651 |
immediate_threats = [detect_threat_motifs(m, THREAT_MOTIFS) for m, _ in active]
|
|
|
643 |
active = [(m, d) for m, d in zip(messages, dates) if m.strip()]
|
644 |
if not active:
|
645 |
return "Please enter at least one message."
|
646 |
+
|
647 |
# Flag any threat phrases present in the messages
|
648 |
+
import re
|
649 |
+
|
650 |
+
def normalize(text):
|
651 |
+
# Lowercase, strip whitespace, and remove most punctuation
|
652 |
+
return re.sub(r"[^a-z0-9 ]", "", text.lower().strip())
|
653 |
+
|
654 |
+
def detect_threat_motifs(message, motif_list):
|
655 |
+
norm_msg = normalize(message)
|
656 |
+
return [
|
657 |
+
motif for motif in motif_list
|
658 |
+
if normalize(motif) in norm_msg
|
659 |
+
]
|
660 |
|
661 |
# Collect matches per message
|
662 |
immediate_threats = [detect_threat_motifs(m, THREAT_MOTIFS) for m, _ in active]
|