Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -172,12 +172,32 @@ sst_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-fin
|
|
172 |
# βββ Single-Message Analysis βββ
|
173 |
def analyze_single_message(text):
|
174 |
# healthy bypass
|
175 |
-
h=healthy_detector(text)[0]
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
with torch.no_grad(): logits=model(**inp).logits.squeeze(0)
|
182 |
probs=torch.sigmoid(logits).numpy()
|
183 |
labels=[lab for lab,p in zip(LABELS,probs) if p>THRESHOLDS[lab]]
|
|
|
172 |
# βββ Single-Message Analysis βββ
|
173 |
def analyze_single_message(text):
|
174 |
# healthy bypass
|
175 |
+
h = healthy_detector(text)[0]
|
176 |
+
|
177 |
+
# 1) Strongly positive β healthy
|
178 |
+
if h['label'] == "POSITIVE" and h['score'] > 0.8:
|
179 |
+
return {
|
180 |
+
"abuse_score": 0,
|
181 |
+
"labels": [],
|
182 |
+
"sentiment": "supportive",
|
183 |
+
"stage": 4,
|
184 |
+
"darvo_score": 0.0,
|
185 |
+
"top_patterns": []
|
186 |
+
}
|
187 |
+
|
188 |
+
# 2) Mildly negative/neutral β also healthy
|
189 |
+
elif h['label'] == "NEGATIVE" and h['score'] < 0.6:
|
190 |
+
return {
|
191 |
+
"abuse_score": 0,
|
192 |
+
"labels": [],
|
193 |
+
"sentiment": "supportive",
|
194 |
+
"stage": 4,
|
195 |
+
"darvo_score": 0.0,
|
196 |
+
"top_patterns": []
|
197 |
+
}
|
198 |
+
|
199 |
+
# β if neither healthy case, continue on to actual abuse detection β
|
200 |
+
inp = tokenizer(text, return_tensors='pt', truncation=True, padding=True)
|
201 |
with torch.no_grad(): logits=model(**inp).logits.squeeze(0)
|
202 |
probs=torch.sigmoid(logits).numpy()
|
203 |
labels=[lab for lab,p in zip(LABELS,probs) if p>THRESHOLDS[lab]]
|