SamanthaStorm commited on
Commit
94d8660
Β·
verified Β·
1 Parent(s): 1bd01b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -26,10 +26,13 @@ THRESHOLDS = {
26
  }
27
 
28
  PATTERN_WEIGHTS = {
29
- "gaslighting": 1.3, "control": 1.2, "dismissiveness": 0.8,
30
- "blame shifting": 0.8, "contradictory statements": 0.75
 
 
 
 
31
  }
32
-
33
  RISK_STAGE_LABELS = {
34
  1: "πŸŒ€ Risk Stage: Tension-Building\nThis message reflects rising emotional pressure or subtle control attempts.",
35
  2: "πŸ”₯ Risk Stage: Escalation\nThis message includes direct or aggressive patterns, suggesting active harm.",
@@ -130,14 +133,15 @@ def get_risk_stage(patterns, sentiment):
130
  return 4
131
  return 1
132
 
133
- def generate_risk_snippet(abuse_score, top_label, escalation_score):
134
  if abuse_score >= 85 or escalation_score >= 16:
135
  risk_level = "high"
136
  elif abuse_score >= 60 or escalation_score >= 8:
137
  risk_level = "moderate"
 
 
138
  else:
139
  risk_level = "low"
140
-
141
  pattern_label = top_label.split(" – ")[0]
142
  pattern_score = top_label.split(" – ")[1] if " – " in top_label else ""
143
 
@@ -266,7 +270,7 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
266
  out += "πŸ“Š This reflects the strength and severity of detected abuse patterns in the message(s).\n\n"
267
  out += f"Escalation Potential: {('High' if escalation_score >= 16 else 'Moderate' if escalation_score >= 8 else 'Low')} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})\n"
268
  out += "🚨 This indicates how many serious risk factors are present based on your answers to the safety checklist.\n\n"
269
- out += generate_risk_snippet(composite_abuse, top_label, escalation_score)
270
  out += f"\n\n{stage_text}"
271
 
272
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
 
26
  }
27
 
28
  PATTERN_WEIGHTS = {
29
+ "gaslighting": 1.3,
30
+ "control": 1.2,
31
+ "dismissiveness": 0.8,
32
+ "blame shifting": 0.8,
33
+ "contradictory statements": 0.75,
34
+ "threat": 1.5 # πŸ”§ New: raise weight for threat
35
  }
 
36
  RISK_STAGE_LABELS = {
37
  1: "πŸŒ€ Risk Stage: Tension-Building\nThis message reflects rising emotional pressure or subtle control attempts.",
38
  2: "πŸ”₯ Risk Stage: Escalation\nThis message includes direct or aggressive patterns, suggesting active harm.",
 
133
  return 4
134
  return 1
135
 
136
+ def generate_risk_snippet(abuse_score, top_label, escalation_score, stage=None):
137
  if abuse_score >= 85 or escalation_score >= 16:
138
  risk_level = "high"
139
  elif abuse_score >= 60 or escalation_score >= 8:
140
  risk_level = "moderate"
141
+ elif stage == 2 and abuse_score >= 40:
142
+ risk_level = "moderate" # πŸ”§ New rule for escalation stage
143
  else:
144
  risk_level = "low"
 
145
  pattern_label = top_label.split(" – ")[0]
146
  pattern_score = top_label.split(" – ")[1] if " – " in top_label else ""
147
 
 
270
  out += "πŸ“Š This reflects the strength and severity of detected abuse patterns in the message(s).\n\n"
271
  out += f"Escalation Potential: {('High' if escalation_score >= 16 else 'Moderate' if escalation_score >= 8 else 'Low')} ({escalation_score}/{sum(w for _, w in ESCALATION_QUESTIONS)})\n"
272
  out += "🚨 This indicates how many serious risk factors are present based on your answers to the safety checklist.\n\n"
273
+ out += generate_risk_snippet(composite_abuse, top_label, escalation_score, most_common_stage)
274
  out += f"\n\n{stage_text}"
275
 
276
  avg_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)