Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -56,6 +56,34 @@ PATTERN_WEIGHTS = {
|
|
56 |
"contradictory statements": 0.75
|
57 |
}
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# --- DARVO Detection Tools ---
|
60 |
DARVO_PATTERNS = {
|
61 |
"blame shifting", "projection", "dismissiveness", "guilt tripping", "contradictory statements"
|
@@ -97,7 +125,6 @@ def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_fo
|
|
97 |
)
|
98 |
return round(min(darvo_score, 1.0), 3)
|
99 |
|
100 |
-
|
101 |
def custom_sentiment(text):
|
102 |
inputs = sentiment_tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
103 |
with torch.no_grad():
|
@@ -168,6 +195,7 @@ def analyze_composite(msg1, msg2, msg3, flags):
|
|
168 |
if average_darvo > 0.25:
|
169 |
darvo_descriptor = "moderate" if average_darvo < 0.65 else "high"
|
170 |
result += f"\n\nDARVO Score: {average_darvo} β This indicates a **{darvo_descriptor} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
|
|
|
171 |
return result
|
172 |
|
173 |
textbox_inputs = [
|
|
|
56 |
"contradictory statements": 0.75
|
57 |
}
|
58 |
|
59 |
+
RISK_SNIPPETS = {
|
60 |
+
"low": (
|
61 |
+
"π’ Risk Level: Low",
|
62 |
+
"The language patterns here do not strongly indicate abuse.",
|
63 |
+
"Continue to check in with yourself and notice how you feel in response to repeated patterns."
|
64 |
+
),
|
65 |
+
"moderate": (
|
66 |
+
"β οΈ Risk Level: Moderate to High",
|
67 |
+
"This language includes control, guilt, or reversal tactics.",
|
68 |
+
"These patterns often lead to emotional confusion and reduced self-trust. Document these messages or talk with someone safe."
|
69 |
+
),
|
70 |
+
"high": (
|
71 |
+
"π Risk Level: High",
|
72 |
+
"Language includes threats or coercive control, which are strong indicators of escalation.",
|
73 |
+
"Consider creating a safety plan or contacting a support line. Trust your sense of unease."
|
74 |
+
)
|
75 |
+
}
|
76 |
+
|
77 |
+
def generate_risk_snippet(abuse_score, top_label):
|
78 |
+
if abuse_score >= 85:
|
79 |
+
risk_level = "high"
|
80 |
+
elif abuse_score >= 60:
|
81 |
+
risk_level = "moderate"
|
82 |
+
else:
|
83 |
+
risk_level = "low"
|
84 |
+
title, summary, advice = RISK_SNIPPETS[risk_level]
|
85 |
+
return f"\n\n{title}\n{summary} (Pattern: **{top_label}**)\nπ‘ {advice}"
|
86 |
+
|
87 |
# --- DARVO Detection Tools ---
|
88 |
DARVO_PATTERNS = {
|
89 |
"blame shifting", "projection", "dismissiveness", "guilt tripping", "contradictory statements"
|
|
|
125 |
)
|
126 |
return round(min(darvo_score, 1.0), 3)
|
127 |
|
|
|
128 |
def custom_sentiment(text):
|
129 |
inputs = sentiment_tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
130 |
with torch.no_grad():
|
|
|
195 |
if average_darvo > 0.25:
|
196 |
darvo_descriptor = "moderate" if average_darvo < 0.65 else "high"
|
197 |
result += f"\n\nDARVO Score: {average_darvo} β This indicates a **{darvo_descriptor} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
|
198 |
+
result += generate_risk_snippet(composite_score, top_label[0])
|
199 |
return result
|
200 |
|
201 |
textbox_inputs = [
|