Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -219,7 +219,7 @@ def get_emotional_tone_tag(emotions, sentiment, patterns, abuse_score):
|
|
219 |
# 5. Emotional Threat
|
220 |
if (
|
221 |
(anger + disgust) > 0.5 and
|
222 |
-
any(p in patterns for p in ["control", "
|
223 |
sentiment == "undermining"
|
224 |
):
|
225 |
return "emotional threat"
|
@@ -350,7 +350,7 @@ def detect_weapon_language(text):
|
|
350 |
text_lower = text.lower()
|
351 |
return any(word in text_lower for word in weapon_keywords)
|
352 |
def get_risk_stage(patterns, sentiment):
|
353 |
-
if "
|
354 |
return 2
|
355 |
elif "recovery phase" in patterns:
|
356 |
return 3
|
@@ -394,7 +394,6 @@ def generate_risk_snippet(abuse_score, top_label, escalation_score, stage):
|
|
394 |
"gaslighting": "This message could be manipulating someone into questioning their perception or feelings.",
|
395 |
"dismissiveness": "This message may include belittling, invalidating, or ignoring the other person’s experience.",
|
396 |
"insults": "Direct insults often appear in escalating abusive dynamics and can erode emotional safety.",
|
397 |
-
"threat": "This message includes threatening language, which is a strong predictor of harm.",
|
398 |
"blame shifting": "This message may redirect responsibility to avoid accountability, especially during conflict.",
|
399 |
"guilt tripping": "This message may induce guilt in order to control or manipulate behavior.",
|
400 |
"recovery phase": "This message may be part of a tension-reset cycle, appearing kind but avoiding change.",
|
@@ -426,7 +425,6 @@ def generate_risk_snippet(abuse_score, top_label, escalation_score, stage):
|
|
426 |
"gaslighting": "This message could be manipulating someone into questioning their perception or feelings.",
|
427 |
"dismissiveness": "This message may include belittling, invalidating, or ignoring the other person’s experience.",
|
428 |
"insults": "Direct insults often appear in escalating abusive dynamics and can erode emotional safety.",
|
429 |
-
"threat": "This message includes threatening language, which is a strong predictor of harm.",
|
430 |
"blame shifting": "This message may redirect responsibility to avoid accountability, especially during conflict.",
|
431 |
"guilt tripping": "This message may induce guilt in order to control or manipulate behavior.",
|
432 |
"recovery phase": "This message may be part of a tension-reset cycle, appearing kind but avoiding change.",
|
@@ -467,7 +465,6 @@ def compute_abuse_score(matched_scores, sentiment):
|
|
467 |
|
468 |
# Pattern floors
|
469 |
FLOORS = {
|
470 |
-
"threat": 70,
|
471 |
"control": 40,
|
472 |
"gaslighting": 30,
|
473 |
"insults": 25,
|
@@ -499,7 +496,7 @@ def analyze_single_message(text, thresholds):
|
|
499 |
# Sentiment override if neutral is high while critical thresholds are passed
|
500 |
if emotion_profile.get("neutral", 0) > 0.85 and any(
|
501 |
scores[LABELS.index(l)] > thresholds[l]
|
502 |
-
for l in ["control", "
|
503 |
):
|
504 |
sentiment = "undermining"
|
505 |
else:
|
@@ -558,7 +555,7 @@ def analyze_single_message(text, thresholds):
|
|
558 |
|
559 |
abuse_score = min(
|
560 |
abuse_score_raw,
|
561 |
-
100 if "
|
562 |
)
|
563 |
|
564 |
# Tag must happen after abuse score is finalized
|
|
|
219 |
# 5. Emotional Threat
|
220 |
if (
|
221 |
(anger + disgust) > 0.5 and
|
222 |
+
any(p in patterns for p in ["control", "insults", "dismissiveness"]) and
|
223 |
sentiment == "undermining"
|
224 |
):
|
225 |
return "emotional threat"
|
|
|
350 |
text_lower = text.lower()
|
351 |
return any(word in text_lower for word in weapon_keywords)
|
352 |
def get_risk_stage(patterns, sentiment):
|
353 |
+
if "insults" in patterns:
|
354 |
return 2
|
355 |
elif "recovery phase" in patterns:
|
356 |
return 3
|
|
|
394 |
"gaslighting": "This message could be manipulating someone into questioning their perception or feelings.",
|
395 |
"dismissiveness": "This message may include belittling, invalidating, or ignoring the other person’s experience.",
|
396 |
"insults": "Direct insults often appear in escalating abusive dynamics and can erode emotional safety.",
|
|
|
397 |
"blame shifting": "This message may redirect responsibility to avoid accountability, especially during conflict.",
|
398 |
"guilt tripping": "This message may induce guilt in order to control or manipulate behavior.",
|
399 |
"recovery phase": "This message may be part of a tension-reset cycle, appearing kind but avoiding change.",
|
|
|
425 |
"gaslighting": "This message could be manipulating someone into questioning their perception or feelings.",
|
426 |
"dismissiveness": "This message may include belittling, invalidating, or ignoring the other person’s experience.",
|
427 |
"insults": "Direct insults often appear in escalating abusive dynamics and can erode emotional safety.",
|
|
|
428 |
"blame shifting": "This message may redirect responsibility to avoid accountability, especially during conflict.",
|
429 |
"guilt tripping": "This message may induce guilt in order to control or manipulate behavior.",
|
430 |
"recovery phase": "This message may be part of a tension-reset cycle, appearing kind but avoiding change.",
|
|
|
465 |
|
466 |
# Pattern floors
|
467 |
FLOORS = {
|
|
|
468 |
"control": 40,
|
469 |
"gaslighting": 30,
|
470 |
"insults": 25,
|
|
|
496 |
# Sentiment override if neutral is high while critical thresholds are passed
|
497 |
if emotion_profile.get("neutral", 0) > 0.85 and any(
|
498 |
scores[LABELS.index(l)] > thresholds[l]
|
499 |
+
for l in ["control", "blame shifting"]
|
500 |
):
|
501 |
sentiment = "undermining"
|
502 |
else:
|
|
|
555 |
|
556 |
abuse_score = min(
|
557 |
abuse_score_raw,
|
558 |
+
100 if "control" in threshold_labels else 95
|
559 |
)
|
560 |
|
561 |
# Tag must happen after abuse score is finalized
|