SamanthaStorm commited on
Commit
4dccd71
Β·
verified Β·
1 Parent(s): 04a0e54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -34
app.py CHANGED
@@ -6,49 +6,49 @@ from transformers import RobertaForSequenceClassification, RobertaTokenizer
6
 
7
  Load custom fine-tuned sentiment model
8
 
9
- sentiment_model = AutoModelForSequenceClassification.from_pretrained("SamanthaStorm/tether-sentiment”)
10
- sentiment_tokenizer = AutoTokenizer.from_pretrained(β€œSamanthaStorm/tether-sentiment”)
11
 
12
  Load abuse pattern model
13
 
14
- model_name = β€œSamanthaStorm/abuse-pattern-detector-v2”
15
  model = RobertaForSequenceClassification.from_pretrained(model_name, trust_remote_code=True)
16
  tokenizer = RobertaTokenizer.from_pretrained(model_name, trust_remote_code=True)
17
 
18
  LABELS = [
19
- "gaslighting”, β€œmockery”, β€œdismissiveness”, β€œcontrol”, β€œguilt_tripping”, β€œapology_baiting”, β€œblame_shifting”, β€œprojection”,
20
- "contradictory_statements”, β€œmanipulation”, β€œdeflection”, β€œinsults”, β€œobscure_formal”, β€œrecovery_phase”, β€œnon_abusive”,
21
- "suicidal_threat”, β€œphysical_threat”, β€œextreme_control”
22
  ]
23
 
24
  THRESHOLDS = {
25
- "gaslighting”: 0.25, β€œmockery”: 0.15, β€œdismissiveness”: 0.30, β€œcontrol”: 0.43, β€œguilt_tripping”: 0.19,
26
- "apology_baiting”: 0.45, β€œblame_shifting”: 0.23, β€œprojection”: 0.50, β€œcontradictory_statements”: 0.25,
27
- "manipulation”: 0.25, β€œdeflection”: 0.30, β€œinsults”: 0.34, β€œobscure_formal”: 0.25, β€œrecovery_phase”: 0.25,
28
- "non_abusive”: 2.0, β€œsuicidal_threat”: 0.45, β€œphysical_threat”: 0.02, β€œextreme_control”: 0.36
29
  }
30
 
31
  PATTERN_LABELS = LABELS[:15]
32
  DANGER_LABELS = LABELS[15:18]
33
 
34
  EXPLANATIONS = {
35
- "gaslighting”: β€œGaslighting involves making someone question their own reality or perceptions…”,
36
- "blame_shifting”: β€œBlame-shifting is when one person redirects the responsibility…”,
37
- "projection”: β€œProjection involves accusing the victim of behaviors the abuser exhibits.”,
38
- "dismissiveness”: β€œDismissiveness is belittling or disregarding another person’s feelings.”,
39
- "mockery”: β€œMockery ridicules someone in a hurtful, humiliating way.”,
40
- "recovery_phase”: β€œRecovery phase dismisses someone’s emotional healing process.”,
41
- "insults”: β€œInsults are derogatory remarks aimed at degrading someone.”,
42
- "apology_baiting”: β€œApology-baiting manipulates victims into apologizing for abuser’s behavior.”,
43
- "deflection”: β€œDeflection avoids accountability by redirecting blame.”,
44
- "control”: β€œControl restricts autonomy through manipulation or coercion.”,
45
- "extreme_control”: β€œExtreme control dominates decisions and behaviors entirely.”,
46
- "physical_threat”: β€œPhysical threats signal risk of bodily harm.”,
47
- "suicidal_threat”: β€œSuicidal threats manipulate others using self-harm threats.”,
48
- "guilt_tripping”: β€œGuilt-tripping uses guilt to manipulate someone’s actions.”,
49
- "manipulation”: β€œManipulation deceives to influence or control outcomes.”,
50
- "non_abusive”: β€œNon-abusive language is respectful and free of coercion.”,
51
- "obscure_formal”: β€œObscure/formal language manipulates through confusion or superiority.”
52
  }
53
 
54
  def custom_sentiment(text):
@@ -60,7 +60,6 @@ label_idx = torch.argmax(probs).item()
60
 
61
  label_map = {0: "supportive", 1: "undermining"}
62
  label = label_map[label_idx]
63
-
64
  score = probs[0][label_idx].item()
65
  return {"label": label, "score": score}
66
 
@@ -114,8 +113,7 @@ else:
114
  resources = "For more information on abuse patterns, consider reaching out to support groups or professional counselors."
115
 
116
  scored_patterns = [
117
- (label, score) for label, score in zip(LABELS, scores)
118
- if label != "non_abusive" and score > adjusted_thresholds[label]
119
  ]
120
  top_patterns = sorted(scored_patterns, key=lambda x: x[1], reverse=True)[:2]
121
 
@@ -142,15 +140,15 @@ return result
142
  iface = gr.Interface(
143
  fn=analyze_messages,
144
  inputs=[
145
- gr.Textbox(lines=10, placeholder=β€œEnter message here…”),
146
  gr.CheckboxGroup(label=β€œDo any of these apply to your situation?”, choices=[
147
- β€œThey’ve threatened harm”, β€œThey isolate me”, β€œI’ve changed my behavior out of fear”,
148
- β€œThey monitor/follow me”, β€œI feel unsafe when alone with them”
149
  ])
150
  ],
151
  outputs=[gr.Textbox(label=β€œAnalysis Result”)],
152
  title=β€œAbuse Pattern Detector”
153
  )
154
 
155
- if name == β€œmain”:
156
  iface.launch()
 
6
 
7
  Load custom fine-tuned sentiment model
8
 
9
+ sentiment_model = AutoModelForSequenceClassification.from_pretrained("SamanthaStorm/tether-sentiment")
10
+ sentiment_tokenizer = AutoTokenizer.from_pretrained("SamanthaStorm/tether-sentiment")
11
 
12
  Load abuse pattern model
13
 
14
+ model_name = "SamanthaStorm/abuse-pattern-detector-v2"
15
  model = RobertaForSequenceClassification.from_pretrained(model_name, trust_remote_code=True)
16
  tokenizer = RobertaTokenizer.from_pretrained(model_name, trust_remote_code=True)
17
 
18
  LABELS = [
19
+ "gaslighting", "mockery", "dismissiveness", "control", "guilt_tripping", "apology_baiting", "blame_shifting", "projection",
20
+ "contradictory_statements", "manipulation", "deflection", "insults", "obscure_formal", "recovery_phase", "non_abusive",
21
+ "suicidal_threat", "physical_threat", "extreme_control"
22
  ]
23
 
24
  THRESHOLDS = {
25
+ "gaslighting": 0.25, "mockery": 0.15, "dismissiveness": 0.30, "control": 0.43, "guilt_tripping": 0.19,
26
+ "apology_baiting": 0.45, "blame_shifting": 0.23, "projection": 0.50, "contradictory_statements": 0.25,
27
+ "manipulation": 0.25, "deflection": 0.30, "insults": 0.34, "obscure_formal": 0.25, "recovery_phase": 0.25,
28
+ "non_abusive": 2.0, "suicidal_threat": 0.45, "physical_threat": 0.02, "extreme_control": 0.36
29
  }
30
 
31
  PATTERN_LABELS = LABELS[:15]
32
  DANGER_LABELS = LABELS[15:18]
33
 
34
  EXPLANATIONS = {
35
+ "gaslighting": "Gaslighting involves making someone question their own reality or perceptions...",
36
+ "blame_shifting": "Blame-shifting is when one person redirects the responsibility...",
37
+ "projection": "Projection involves accusing the victim of behaviors the abuser exhibits.",
38
+ "dismissiveness": "Dismissiveness is belittling or disregarding another person’s feelings.",
39
+ "mockery": "Mockery ridicules someone in a hurtful, humiliating way.",
40
+ "recovery_phase": "Recovery phase dismisses someone's emotional healing process.",
41
+ "insults": "Insults are derogatory remarks aimed at degrading someone.",
42
+ "apology_baiting": "Apology-baiting manipulates victims into apologizing for abuser's behavior.",
43
+ "deflection": "Deflection avoids accountability by redirecting blame.",
44
+ "control": "Control restricts autonomy through manipulation or coercion.",
45
+ "extreme_control": "Extreme control dominates decisions and behaviors entirely.",
46
+ "physical_threat": "Physical threats signal risk of bodily harm.",
47
+ "suicidal_threat": "Suicidal threats manipulate others using self-harm threats.",
48
+ "guilt_tripping": "Guilt-tripping uses guilt to manipulate someone’s actions.",
49
+ "manipulation": "Manipulation deceives to influence or control outcomes.",
50
+ "non_abusive": "Non-abusive language is respectful and free of coercion.",
51
+ "obscure_formal": "Obscure/formal language manipulates through confusion or superiority."
52
  }
53
 
54
  def custom_sentiment(text):
 
60
 
61
  label_map = {0: "supportive", 1: "undermining"}
62
  label = label_map[label_idx]
 
63
  score = probs[0][label_idx].item()
64
  return {"label": label, "score": score}
65
 
 
113
  resources = "For more information on abuse patterns, consider reaching out to support groups or professional counselors."
114
 
115
  scored_patterns = [
116
+ (label, score) for label, score in zip(PATTERN_LABELS, scores[:15]) if label != "non_abusive"
 
117
  ]
118
  top_patterns = sorted(scored_patterns, key=lambda x: x[1], reverse=True)[:2]
119
 
 
140
  iface = gr.Interface(
141
  fn=analyze_messages,
142
  inputs=[
143
+ gr.Textbox(lines=10, placeholder="Enter message here…"),
144
  gr.CheckboxGroup(label=β€œDo any of these apply to your situation?”, choices=[
145
+ "They’ve threatened harm", "They isolate me", "I’ve changed my behavior out of fear",
146
+ "They monitor/follow me", "I feel unsafe when alone with them"
147
  ])
148
  ],
149
  outputs=[gr.Textbox(label=β€œAnalysis Result”)],
150
  title=β€œAbuse Pattern Detector”
151
  )
152
 
153
+ if name == "main":
154
  iface.launch()