Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,7 @@ LABELS = [
|
|
37 |
THRESHOLDS = {
|
38 |
"blame shifting": 0.3,
|
39 |
"contradictory statements": 0.32,
|
40 |
-
"control": 0.
|
41 |
"dismissiveness": 0.45,
|
42 |
"gaslighting": 0.30,
|
43 |
"guilt tripping": 0.20,
|
@@ -188,19 +188,36 @@ def analyze_single_message(text, thresholds, motif_flags):
|
|
188 |
|
189 |
# --- Composite Message Analysis ---
|
190 |
def analyze_composite(msg1, msg2, msg3, flags):
|
191 |
-
thresholds = THRESHOLDS
|
192 |
messages = [msg1, msg2, msg3]
|
193 |
active_messages = [m for m in messages if m.strip()]
|
194 |
if not active_messages:
|
195 |
return "Please enter at least one message."
|
196 |
|
197 |
results = []
|
|
|
|
|
|
|
198 |
for m in active_messages:
|
199 |
result = analyze_single_message(m, thresholds, flags)
|
200 |
print(f"Message: {m}")
|
201 |
print(f"Sentiment result: {result[4]}")
|
202 |
results.append(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
|
|
204 |
abuse_scores = [r[0] for r in results]
|
205 |
darvo_scores = [r[3] for r in results]
|
206 |
average_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
|
@@ -218,7 +235,6 @@ def analyze_composite(msg1, msg2, msg3, flags):
|
|
218 |
"They monitor/follow me": 4,
|
219 |
"I feel unsafe when alone with them": 6
|
220 |
}
|
221 |
-
|
222 |
flag_boost = sum(flag_weights.get(f, 3) for f in flags) / len(active_messages)
|
223 |
composite_score = min(base_score + flag_boost, 100)
|
224 |
if len(active_messages) == 1:
|
@@ -234,6 +250,10 @@ def analyze_composite(msg1, msg2, msg3, flags):
|
|
234 |
darvo_descriptor = "moderate" if average_darvo < 0.65 else "high"
|
235 |
result += f"\n\nDARVO Score: {average_darvo} → This indicates a **{darvo_descriptor} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
|
236 |
result += generate_risk_snippet(composite_score, top_label[0])
|
|
|
|
|
|
|
|
|
237 |
return result
|
238 |
|
239 |
# --- Gradio Interface ---
|
|
|
37 |
THRESHOLDS = {
|
38 |
"blame shifting": 0.3,
|
39 |
"contradictory statements": 0.32,
|
40 |
+
"control": 0.45,
|
41 |
"dismissiveness": 0.45,
|
42 |
"gaslighting": 0.30,
|
43 |
"guilt tripping": 0.20,
|
|
|
188 |
|
189 |
# --- Composite Message Analysis ---
|
190 |
def analyze_composite(msg1, msg2, msg3, flags):
|
191 |
+
thresholds = THRESHOLDS.copy()
|
192 |
messages = [msg1, msg2, msg3]
|
193 |
active_messages = [m for m in messages if m.strip()]
|
194 |
if not active_messages:
|
195 |
return "Please enter at least one message."
|
196 |
|
197 |
results = []
|
198 |
+
sentiment_labels = []
|
199 |
+
sentiment_score_total = 0.0
|
200 |
+
|
201 |
for m in active_messages:
|
202 |
result = analyze_single_message(m, thresholds, flags)
|
203 |
print(f"Message: {m}")
|
204 |
print(f"Sentiment result: {result[4]}")
|
205 |
results.append(result)
|
206 |
+
sentiment_labels.append(result[4]["label"])
|
207 |
+
if result[4]["label"] == "undermining":
|
208 |
+
sentiment_score_total += 0.5 # fixed value from `analyze_single_message`
|
209 |
+
|
210 |
+
# Sentiment adjustment based on average and balance
|
211 |
+
undermining_count = sentiment_labels.count("undermining")
|
212 |
+
supportive_count = sentiment_labels.count("supportive")
|
213 |
+
|
214 |
+
if undermining_count > supportive_count:
|
215 |
+
thresholds = {k: v * 0.9 for k, v in thresholds.items()}
|
216 |
+
elif undermining_count and supportive_count:
|
217 |
+
thresholds = {k: v * 0.95 for k, v in thresholds.items()} # very subtle if mixed
|
218 |
+
print("⚖️ Detected conflicting sentiment across messages.")
|
219 |
|
220 |
+
# Abuse scoring
|
221 |
abuse_scores = [r[0] for r in results]
|
222 |
darvo_scores = [r[3] for r in results]
|
223 |
average_darvo = round(sum(darvo_scores) / len(darvo_scores), 3)
|
|
|
235 |
"They monitor/follow me": 4,
|
236 |
"I feel unsafe when alone with them": 6
|
237 |
}
|
|
|
238 |
flag_boost = sum(flag_weights.get(f, 3) for f in flags) / len(active_messages)
|
239 |
composite_score = min(base_score + flag_boost, 100)
|
240 |
if len(active_messages) == 1:
|
|
|
250 |
darvo_descriptor = "moderate" if average_darvo < 0.65 else "high"
|
251 |
result += f"\n\nDARVO Score: {average_darvo} → This indicates a **{darvo_descriptor} likelihood** of narrative reversal (DARVO), where the speaker may be denying, attacking, or reversing blame."
|
252 |
result += generate_risk_snippet(composite_score, top_label[0])
|
253 |
+
|
254 |
+
if undermining_count and supportive_count:
|
255 |
+
result += "\n\n⚖️ These messages contain **conflicting emotional tones** — this may indicate mixed signals, ambivalence, or a push-pull dynamic. Use caution interpreting any one message alone."
|
256 |
+
|
257 |
return result
|
258 |
|
259 |
# --- Gradio Interface ---
|