Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -108,6 +108,38 @@ def analyze_single_message(text, thresholds):
|
|
108 |
stage = get_risk_stage(threshold_labels, sentiment)
|
109 |
|
110 |
return abuse_score, threshold_labels, top_patterns, result, stage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
113 |
responses = answers_and_none[:len(ESCALATION_QUESTIONS)]
|
|
|
108 |
stage = get_risk_stage(threshold_labels, sentiment)
|
109 |
|
110 |
return abuse_score, threshold_labels, top_patterns, result, stage
|
111 |
+
|
112 |
+
def generate_risk_snippet(abuse_score, top_label, escalation_score):
|
113 |
+
if abuse_score >= 85 or escalation_score >= 16:
|
114 |
+
risk_level = "high"
|
115 |
+
elif abuse_score >= 60 or escalation_score >= 8:
|
116 |
+
risk_level = "moderate"
|
117 |
+
else:
|
118 |
+
risk_level = "low"
|
119 |
+
|
120 |
+
pattern_label = top_label.split(" – ")[0]
|
121 |
+
pattern_score = top_label.split(" – ")[1] if " – " in top_label else ""
|
122 |
+
|
123 |
+
base = f"\n\n🛑 Risk Level: {risk_level.capitalize()}\n"
|
124 |
+
base += f"This message shows strong indicators of **{pattern_label}**. "
|
125 |
+
|
126 |
+
if risk_level == "high":
|
127 |
+
base += "The language may reflect patterns of emotional control, even when expressed in soft or caring terms.\n"
|
128 |
+
elif risk_level == "moderate":
|
129 |
+
base += "There are signs of emotional pressure or indirect control that may escalate if repeated.\n"
|
130 |
+
else:
|
131 |
+
base += "The message does not strongly indicate abuse, but it's important to monitor for patterns.\n"
|
132 |
+
|
133 |
+
base += "\n💡 *Why this might be flagged:*\n"
|
134 |
+
base += (
|
135 |
+
"This message may seem supportive, but language like “Do you need me to come home?” can sometimes carry implied pressure, especially if declining leads to guilt, tension, or emotional withdrawal. "
|
136 |
+
"The model looks for patterns that reflect subtle coercion, obligation, or reversal dynamics—even when not overtly aggressive.\n"
|
137 |
+
)
|
138 |
+
|
139 |
+
base += f"\nDetected Pattern: **{pattern_label} ({pattern_score})**\n"
|
140 |
+
base += "🧠 You can review the pattern in context. This tool highlights possible dynamics—not judgments."
|
141 |
+
|
142 |
+
return base
|
143 |
|
144 |
def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
145 |
responses = answers_and_none[:len(ESCALATION_QUESTIONS)]
|