SamanthaStorm commited on
Commit
7119e2f
·
verified ·
1 Parent(s): 21421a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -49,6 +49,9 @@ ESCALATION_QUESTIONS = [
49
  ("Violence has increased in frequency or severity", 3),
50
  ("Partner monitors your calls/GPS/social media", 2)
51
  ]
 
 
 
52
  DARVO_MOTIFS = [
53
  "I never said that.", "You’re imagining things.", "That never happened.",
54
  "You’re making a big deal out of nothing.", "It was just a joke.", "You’re too sensitive.",
@@ -180,13 +183,7 @@ def analyze_single_message(text, thresholds):
180
  }
181
 
182
  contradiction_flag = detect_contradiction(text)
183
- motifs = [phrase for _, phrase in matched_phrases]
184
- darvo_score = calculate_darvo_score(
185
- pattern_labels,
186
- sentiment_before=0.0,
187
- sentiment_after=sentiment_score,
188
- motifs_found=motifs,
189
- contradiction_flag=contradiction_flag
190
  )
191
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
192
  with torch.no_grad():
@@ -197,6 +194,13 @@ def analyze_single_message(text, thresholds):
197
  label for label, score in zip(LABELS, scores)
198
  if score > adjusted_thresholds[label]
199
  ]
 
 
 
 
 
 
 
200
 
201
  top_patterns = sorted(
202
  [(label, score) for label, score in zip(LABELS, scores)],
@@ -254,9 +258,6 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
254
  most_common_stage = max(set(stages), key=stages.count)
255
  stage_text = RISK_STAGE_LABELS[most_common_stage]
256
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
257
- if avg_darvo > 0.25:
258
- level = "moderate" if avg_darvo < 0.65 else "high"
259
- out += f"\n\n🎭 **DARVO Score: {avg_darvo}** → This indicates a **{level} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
260
  top_label = f"{top_labels[0]} – {int(round(top_scores[0] * 100))}%"
261
  composite_abuse = int(round(sum(abuse_scores) / len(abuse_scores)))
262
 
@@ -268,7 +269,7 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
268
  out += f"\n\n{stage_text}"
269
 
270
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
271
- if avg_darvo > 0.25:
272
  level = "moderate" if avg_darvo < 0.65 else "high"
273
  out += f"\n\n🎭 **DARVO Score: {avg_darvo}** → This indicates a **{level} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
274
 
 
49
  ("Violence has increased in frequency or severity", 3),
50
  ("Partner monitors your calls/GPS/social media", 2)
51
  ]
52
+ DARVO_PATTERNS = {
53
+ "blame shifting", "projection", "dismissiveness", "guilt tripping", "contradictory statements"
54
+ }
55
  DARVO_MOTIFS = [
56
  "I never said that.", "You’re imagining things.", "That never happened.",
57
  "You’re making a big deal out of nothing.", "It was just a joke.", "You’re too sensitive.",
 
183
  }
184
 
185
  contradiction_flag = detect_contradiction(text)
186
+
 
 
 
 
 
 
187
  )
188
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
189
  with torch.no_grad():
 
194
  label for label, score in zip(LABELS, scores)
195
  if score > adjusted_thresholds[label]
196
  ]
197
+ motifs = [phrase for _, phrase in matched_phrases]
198
+ darvo_score = calculate_darvo_score(
199
+ pattern_labels,
200
+ sentiment_before=0.0,
201
+ sentiment_after=sentiment_score,
202
+ motifs_found=motifs,
203
+ contradiction_flag=contradiction_flag
204
 
205
  top_patterns = sorted(
206
  [(label, score) for label, score in zip(LABELS, scores)],
 
258
  most_common_stage = max(set(stages), key=stages.count)
259
  stage_text = RISK_STAGE_LABELS[most_common_stage]
260
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
 
 
 
261
  top_label = f"{top_labels[0]} – {int(round(top_scores[0] * 100))}%"
262
  composite_abuse = int(round(sum(abuse_scores) / len(abuse_scores)))
263
 
 
269
  out += f"\n\n{stage_text}"
270
 
271
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
272
+ if avg_darvo > 0.25:
273
  level = "moderate" if avg_darvo < 0.65 else "high"
274
  out += f"\n\n🎭 **DARVO Score: {avg_darvo}** → This indicates a **{level} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
275