SamanthaStorm commited on
Commit
6481f86
Β·
verified Β·
1 Parent(s): b40c9cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
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
- if h['label']=="POSITIVE" and h['score']>0.9:
177
- return { "abuse_score":0, "labels":[], "sentiment":"supportive",
178
- "stage":4, "darvo_score":0.0, "top_patterns":[] }
179
- # model
180
- inp=tokenizer(text,return_tensors='pt',truncation=True,padding=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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]]