Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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(
|
11 |
|
12 |
Load abuse pattern model
|
13 |
|
14 |
-
model_name =
|
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
|
20 |
-
"contradictory_statements
|
21 |
-
"suicidal_threat
|
22 |
]
|
23 |
|
24 |
THRESHOLDS = {
|
25 |
-
"gaslighting
|
26 |
-
"apology_baiting
|
27 |
-
"manipulation
|
28 |
-
"non_abusive
|
29 |
}
|
30 |
|
31 |
PATTERN_LABELS = LABELS[:15]
|
32 |
DANGER_LABELS = LABELS[15:18]
|
33 |
|
34 |
EXPLANATIONS = {
|
35 |
-
"gaslighting
|
36 |
-
"blame_shifting
|
37 |
-
"projection
|
38 |
-
"dismissiveness
|
39 |
-
"mockery
|
40 |
-
"recovery_phase
|
41 |
-
"insults
|
42 |
-
"apology_baiting
|
43 |
-
"deflection
|
44 |
-
"control
|
45 |
-
"extreme_control
|
46 |
-
"physical_threat
|
47 |
-
"suicidal_threat
|
48 |
-
"guilt_tripping
|
49 |
-
"manipulation
|
50 |
-
"non_abusive
|
51 |
-
"obscure_formal
|
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(
|
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
|
146 |
gr.CheckboxGroup(label=βDo any of these apply to your situation?β, choices=[
|
147 |
-
|
148 |
-
|
149 |
])
|
150 |
],
|
151 |
outputs=[gr.Textbox(label=βAnalysis Resultβ)],
|
152 |
title=βAbuse Pattern Detectorβ
|
153 |
)
|
154 |
|
155 |
-
if name ==
|
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()
|