Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -627,7 +627,7 @@ def analyze_single_message(text, thresholds):
|
|
627 |
|
628 |
return abuse_score, threshold_labels, top_patterns, {"label": sentiment}, stage, darvo_score, tone_tag
|
629 |
|
630 |
-
def analyze_composite(msg1,
|
631 |
from collections import Counter
|
632 |
|
633 |
none_selected_checked = answers_and_none[-1]
|
@@ -639,8 +639,7 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
|
|
639 |
escalation_score = sum(w for (_, w), a in zip(ESCALATION_QUESTIONS, answers_and_none[:-1]) if a)
|
640 |
|
641 |
messages = [msg1, msg2, msg3]
|
642 |
-
|
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 |
|
@@ -671,7 +670,7 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
|
|
671 |
stages = [r[0][4] for r in results]
|
672 |
darvo_scores = [r[0][5] for r in results]
|
673 |
tone_tags = [r[0][6] for r in results]
|
674 |
-
dates_used = [r[1]
|
675 |
|
676 |
predicted_labels = [label for r in results for label, _ in r[0][2]]
|
677 |
high = {'control'}
|
@@ -772,18 +771,12 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
|
|
772 |
out += "\n\n🧩 **Immediate Danger Threats:** None explicitly detected.\n"
|
773 |
out += "This does *not* rule out risk, but no direct threat phrases were matched."
|
774 |
pattern_labels = [r[0][2][0][0] for r in results]
|
775 |
-
timeline_image = generate_abuse_score_chart(dates_used
|
776 |
out += "\n\n" + escalation_text
|
777 |
|
778 |
return out, timeline_image
|
779 |
|
780 |
-
|
781 |
-
(
|
782 |
-
gr.Textbox(label=f"Message {i+1}"),
|
783 |
-
gr.Textbox(label=f"Date {i+1} (optional)", placeholder="YYYY-MM-DD")
|
784 |
-
)
|
785 |
-
for i in range(3)
|
786 |
-
]
|
787 |
textbox_inputs = [item for pair in message_date_pairs for item in pair]
|
788 |
quiz_boxes = [gr.Checkbox(label=q) for q, _ in ESCALATION_QUESTIONS]
|
789 |
none_box = gr.Checkbox(label="None of the above")
|
@@ -796,8 +789,10 @@ iface = gr.Interface(
|
|
796 |
gr.Image(label="Abuse Score Timeline", type="pil")
|
797 |
],
|
798 |
title="Abuse Pattern Detector + Escalation Quiz",
|
|
|
799 |
allow_flagging="manual"
|
800 |
)
|
|
|
801 |
|
802 |
if __name__ == "__main__":
|
803 |
iface.launch()
|
|
|
627 |
|
628 |
return abuse_score, threshold_labels, top_patterns, {"label": sentiment}, stage, darvo_score, tone_tag
|
629 |
|
630 |
+
def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
631 |
from collections import Counter
|
632 |
|
633 |
none_selected_checked = answers_and_none[-1]
|
|
|
639 |
escalation_score = sum(w for (_, w), a in zip(ESCALATION_QUESTIONS, answers_and_none[:-1]) if a)
|
640 |
|
641 |
messages = [msg1, msg2, msg3]
|
642 |
+
active = [(m, f"Message {i+1}") for i, m in enumerate(messages) if m.strip()]
|
|
|
643 |
if not active:
|
644 |
return "Please enter at least one message."
|
645 |
|
|
|
670 |
stages = [r[0][4] for r in results]
|
671 |
darvo_scores = [r[0][5] for r in results]
|
672 |
tone_tags = [r[0][6] for r in results]
|
673 |
+
dates_used = [r[1] for r in results]
|
674 |
|
675 |
predicted_labels = [label for r in results for label, _ in r[0][2]]
|
676 |
high = {'control'}
|
|
|
771 |
out += "\n\n🧩 **Immediate Danger Threats:** None explicitly detected.\n"
|
772 |
out += "This does *not* rule out risk, but no direct threat phrases were matched."
|
773 |
pattern_labels = [r[0][2][0][0] for r in results]
|
774 |
+
timeline_image = generate_abuse_score_chart(dates_used abuse_scores, pattern_labels)
|
775 |
out += "\n\n" + escalation_text
|
776 |
|
777 |
return out, timeline_image
|
778 |
|
779 |
+
textbox_inputs = [gr.Textbox(label=f"Message {i+1}") for i in range(3)]
|
|
|
|
|
|
|
|
|
|
|
|
|
780 |
textbox_inputs = [item for pair in message_date_pairs for item in pair]
|
781 |
quiz_boxes = [gr.Checkbox(label=q) for q, _ in ESCALATION_QUESTIONS]
|
782 |
none_box = gr.Checkbox(label="None of the above")
|
|
|
789 |
gr.Image(label="Abuse Score Timeline", type="pil")
|
790 |
],
|
791 |
title="Abuse Pattern Detector + Escalation Quiz",
|
792 |
+
description="Enter up to three messages that concern you. For the most accurate results, enter messages that happened during a recent time period that felt emotionally intense or 'off.'",
|
793 |
allow_flagging="manual"
|
794 |
)
|
795 |
+
)
|
796 |
|
797 |
if __name__ == "__main__":
|
798 |
iface.launch()
|