SamanthaStorm commited on
Commit
eb5a544
·
verified ·
1 Parent(s): 15de668

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -6
app.py CHANGED
@@ -138,11 +138,71 @@ DARVO_MOTIFS = [
138
  "You’re the one who’s always making me feel like I’m the one who’s abusive.",
139
  "You’re the one who’s always making me feel like I’m the one who’s toxic."
140
  ]
141
- def get_emotion_profile(text):
142
- emotions = emotion_pipeline(text)
143
- if isinstance(emotions, list) and isinstance(emotions[0], list):
144
- emotions = emotions[0] # unwrap nested list
145
- return {e['label'].lower(): round(e['score'], 3) for e in emotions}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  def detect_contradiction(message):
147
  patterns = [
148
  (r"\b(i love you).{0,15}(i hate you|you ruin everything)", re.IGNORECASE),
@@ -280,7 +340,8 @@ def analyze_single_message(text, thresholds):
280
  emotion_profile = get_emotion_profile(text)
281
  sentiment_score = emotion_profile.get("anger", 0) + emotion_profile.get("disgust", 0)
282
  sentiment = "undermining" if sentiment_score > 0.4 else "supportive"
283
-
 
284
  weapon_flag = detect_weapon_language(text)
285
 
286
  adjusted_thresholds = {
 
138
  "You’re the one who’s always making me feel like I’m the one who’s abusive.",
139
  "You’re the one who’s always making me feel like I’m the one who’s toxic."
140
  ]
141
+ def get_emotional_tone_tag(emotions, sentiment, patterns, abuse_score):
142
+ sadness = emotions.get("sadness", 0)
143
+ joy = emotions.get("joy", 0)
144
+ neutral = emotions.get("neutral", 0)
145
+ disgust = emotions.get("disgust", 0)
146
+ anger = emotions.get("anger", 0)
147
+ fear = emotions.get("fear", 0)
148
+
149
+ # 1. Performative Regret
150
+ if (
151
+ sadness > 0.4 and
152
+ any(p in patterns for p in ["blame shifting", "guilt tripping", "recovery phase"]) and
153
+ (sentiment == "undermining" or abuse_score > 40)
154
+ ):
155
+ return "performative regret"
156
+
157
+ # 2. Coercive Warmth
158
+ if (
159
+ (joy > 0.3 or sadness > 0.4) and
160
+ any(p in patterns for p in ["control", "gaslighting"]) and
161
+ sentiment == "undermining"
162
+ ):
163
+ return "coercive warmth"
164
+
165
+ # 3. Cold Invalidation
166
+ if (
167
+ (neutral + disgust) > 0.5 and
168
+ any(p in patterns for p in ["dismissiveness", "projection", "obscure language"]) and
169
+ sentiment == "undermining"
170
+ ):
171
+ return "cold invalidation"
172
+
173
+ # 4. Genuine Vulnerability
174
+ if (
175
+ (sadness + fear) > 0.5 and
176
+ sentiment == "supportive" and
177
+ all(p in ["recovery phase"] for p in patterns)
178
+ ):
179
+ return "genuine vulnerability"
180
+
181
+ # 5. Emotional Threat
182
+ if (
183
+ (anger + disgust) > 0.5 and
184
+ any(p in patterns for p in ["control", "threat", "insults", "dismissiveness"]) and
185
+ sentiment == "undermining"
186
+ ):
187
+ return "emotional threat"
188
+
189
+ # 6. Weaponized Sadness
190
+ if (
191
+ sadness > 0.6 and
192
+ any(p in patterns for p in ["guilt tripping", "projection"]) and
193
+ sentiment == "undermining"
194
+ ):
195
+ return "weaponized sadness"
196
+
197
+ # 7. Toxic Resignation
198
+ if (
199
+ neutral > 0.5 and
200
+ any(p in patterns for p in ["dismissiveness", "obscure language"]) and
201
+ sentiment == "undermining"
202
+ ):
203
+ return "toxic resignation"
204
+
205
+ return None
206
  def detect_contradiction(message):
207
  patterns = [
208
  (r"\b(i love you).{0,15}(i hate you|you ruin everything)", re.IGNORECASE),
 
340
  emotion_profile = get_emotion_profile(text)
341
  sentiment_score = emotion_profile.get("anger", 0) + emotion_profile.get("disgust", 0)
342
  sentiment = "undermining" if sentiment_score > 0.4 else "supportive"
343
+ tone_tag = get_emotional_tone_tag(emotion_profile, sentiment, threshold_labels, abuse_score)
344
+ print(f"Emotional Tone Tag: {tone_tag}")
345
  weapon_flag = detect_weapon_language(text)
346
 
347
  adjusted_thresholds = {