SamanthaStorm commited on
Commit
99463df
·
verified ·
1 Parent(s): 44dafc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -23,9 +23,9 @@ THRESHOLDS = {
23
  "mockery": 0.15,
24
  "dismissiveness": 0.30, # original value, not 0.30
25
  "control": 0.43,
26
- "guilt_tripping": 0.24,
27
  "apology_baiting": 0.45,
28
- "blame_shifting": 0.31,
29
  "projection": 0.50,
30
  "contradictory_statements": 0.25,
31
  "manipulation": 0.25,
@@ -36,12 +36,12 @@ THRESHOLDS = {
36
  "suicidal_threat": 0.45,
37
  "physical_threat": 0.31,
38
  "extreme_control": 0.36,
39
- "non_abusive": 0.35
40
  }
41
 
42
  # Define label groups using slicing (first 14: abuse patterns, last 3: danger cues)
43
- PATTERN_LABELS = LABELS[:14]
44
- DANGER_LABELS = LABELS[14:]
45
 
46
  def calculate_abuse_level(scores, thresholds):
47
  triggered_scores = [score for label, score in zip(LABELS, scores) if score > thresholds[label]]
@@ -73,8 +73,13 @@ def analyze_messages(input_text):
73
  scores = torch.sigmoid(outputs.logits.squeeze(0)).numpy()
74
 
75
  # Count the number of triggered abuse pattern and danger flags based on thresholds
76
- pattern_count = sum(score > THRESHOLDS[label] for label, score in zip(PATTERN_LABELS, scores[:14]))
77
- danger_flag_count = sum(score > THRESHOLDS[label] for label, score in zip(DANGER_LABELS, scores[14:]))
 
 
 
 
 
78
 
79
  # Calculate overall abuse level and interpret it
80
  abuse_level = calculate_abuse_level(scores, THRESHOLDS)
 
23
  "mockery": 0.15,
24
  "dismissiveness": 0.30, # original value, not 0.30
25
  "control": 0.43,
26
+ "guilt_tripping": 0.19,
27
  "apology_baiting": 0.45,
28
+ "blame_shifting": 0.23,
29
  "projection": 0.50,
30
  "contradictory_statements": 0.25,
31
  "manipulation": 0.25,
 
36
  "suicidal_threat": 0.45,
37
  "physical_threat": 0.31,
38
  "extreme_control": 0.36,
39
+ "non_abusive": 0.40
40
  }
41
 
42
  # Define label groups using slicing (first 14: abuse patterns, last 3: danger cues)
43
+ PATTERN_LABELS = LABELS[:17]
44
+ DANGER_LABELS = LABELS[17:]
45
 
46
  def calculate_abuse_level(scores, thresholds):
47
  triggered_scores = [score for label, score in zip(LABELS, scores) if score > thresholds[label]]
 
73
  scores = torch.sigmoid(outputs.logits.squeeze(0)).numpy()
74
 
75
  # Count the number of triggered abuse pattern and danger flags based on thresholds
76
+ pattern_count = sum(score > THRESHOLDS[label] for label, score in zip(PATTERN_LABELS, scores[:17]))
77
+ danger_flag_count = sum(score > THRESHOLDS[label] for label, score in zip(DANGER_LABELS, scores[17:]))
78
+ # Build formatted raw score display
79
+ score_lines = [
80
+ f"{label:25}: {score:.3f}" for label, score in zip(PATTERN_LABELS + DANGER_LABELS, scores)
81
+ ]
82
+ raw_score_output = "\n".join(score_lines)
83
 
84
  # Calculate overall abuse level and interpret it
85
  abuse_level = calculate_abuse_level(scores, THRESHOLDS)