SamanthaStorm commited on
Commit
49b9d9d
·
verified ·
1 Parent(s): a20729d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -66
app.py CHANGED
@@ -105,95 +105,117 @@ def get_emotional_tone_tag(emotion_profile, patterns, text_lower):
105
  emo: sum(EMOLEX.get(w, {}).get(emo, 0) for w in words)
106
  for emo in ["anger","joy","sadness","fear","disgust"]
107
  }
108
-
109
- # 0. Support override: explicit keywords or detected joy in lexicon
110
- if any(k in text_lower for k in ["support", "hope", "grace"]) or lex_counts["joy"] > 0:
111
  return "supportive"
112
 
113
- # 1. Performative Regret
114
- if (sadness > 0.4 or lex_counts["sadness"] > 1) \
115
- and any(p in patterns for p in ["blame shifting","guilt tripping","recovery phase"]):
116
  return "performative regret"
117
 
118
- # 2. Coercive Warmth
119
- if ((joy > 0.3 or lex_counts["joy"] > 1) or (sadness > 0.4 or lex_counts["sadness"] > 1)) \
120
- and any(p in patterns for p in ["control","gaslighting"]):
121
- return "coercive warmth"
 
122
 
123
- # 3. Cold Invalidation
124
- if ((neutral + disgust) > 0.5 or lex_counts["disgust"] > 1) \
 
125
  and any(p in patterns for p in ["dismissiveness","projection","obscure language"]):
126
- return "cold invalidation"
127
 
128
- # 4. Genuine Vulnerability
129
- if ((sadness + fear) > 0.5 or (lex_counts["sadness"] + lex_counts["fear"]) > 1) \
 
130
  and all(p == "recovery phase" for p in patterns):
131
- return "genuine vulnerability"
132
 
133
- # 5. Emotional Threat
134
- if ((anger + disgust) > 0.5 or (lex_counts["anger"] + lex_counts["disgust"]) > 1) \
 
135
  and any(p in patterns for p in ["control","threat","insults","dismissiveness"]):
136
- return "emotional threat"
137
 
138
- # 6. Weaponized Sadness
139
- if (sadness > 0.6 or lex_counts["sadness"] > 2) \
 
140
  and any(p in patterns for p in ["guilt tripping","projection"]):
141
- return "weaponized sadness"
142
 
143
- # 7. Toxic Resignation
144
- if (neutral > 0.5) and any(p in patterns for p in ["dismissiveness","obscure language"]):
145
- return "toxic resignation"
 
 
146
 
147
- # 8. Indignant Reproach
148
- if (anger > 0.5 or lex_counts["anger"] > 1) \
 
149
  and any(p in patterns for p in ["guilt tripping","contradictory statements"]):
150
- return "indignant reproach"
151
-
152
- # 9. Confrontational
153
- if (anger > 0.6 or lex_counts["anger"] > 1) and patterns:
154
- return "confrontational"
155
-
156
- # 10. Passive Aggression
157
- if (neutral > 0.6) and any(p in patterns for p in ["dismissiveness","projection"]):
158
- return "passive aggression"
159
-
160
- # 11. Sarcastic Mockery
161
- if (joy > 0.3 or lex_counts["joy"] > 1) and "insults" in patterns:
162
- return "sarcastic mockery"
163
-
164
- # 12. Menacing Threat
165
- if (fear > 0.3 or lex_counts["fear"] > 0) and "threat" in patterns:
166
- return "menacing threat"
167
-
168
- # 13. Pleading Concern
169
- if (sadness > 0.3 or lex_counts["sadness"] > 0) \
 
 
 
 
 
 
 
 
 
170
  and any(k in text_lower for k in APOLOGY_KEYWORDS) \
171
  and not patterns:
172
- return "pleading concern"
173
 
174
- # 14. Fear-mongering
175
- if ((fear + disgust) > 0.5 or (lex_counts["fear"] + lex_counts["disgust"]) > 1) \
 
176
  and "projection" in patterns:
177
- return "fear-mongering"
178
 
179
- # 15. Disbelieving Accusation
180
- if (surprise > 0.3 or lex_counts.get("surprise",0) > 0) \
 
181
  and "blame shifting" in patterns:
182
- return "disbelieving accusation"
183
 
184
- # 16. Empathetic Solidarity
185
- if (joy > 0.2 and sadness > 0.2) \
186
- and (lex_counts["joy"] > 0 and lex_counts["sadness"] > 0) \
187
  and not patterns:
188
- return "empathetic solidarity"
189
-
190
- # 17. Assertive Boundary
191
- if (anger > 0.4 or lex_counts["anger"] > 0) and "control" in patterns:
192
- return "assertive boundary"
193
-
194
- # 18. Stonewalling
195
- if neutral > 0.7 and not patterns:
196
- return "stonewalling"
 
 
 
 
197
 
198
  return None
199
 
 
105
  emo: sum(EMOLEX.get(w, {}).get(emo, 0) for w in words)
106
  for emo in ["anger","joy","sadness","fear","disgust"]
107
  }
108
+ # 0. Support override
109
+ if lex_counts["joy"] > 0 and any(k in text_lower for k in ["support","hope","grace"]):
 
110
  return "supportive"
111
 
112
+ # 1. Performative Regret
113
+ if sadness > 0.4 \
114
+ and (lex_counts["sadness"] > 0 or any(p in patterns for p in ["blame shifting","guilt tripping","recovery phase"])):
115
  return "performative regret"
116
 
117
+ # 2. Coercive Warmth
118
+ if (joy > 0.3 or sadness > 0.4) \
119
+ and (lex_counts["joy"] > 0 or lex_counts["sadness"] > 0) \
120
+ and any(p in patterns for p in ["control","gaslighting"]):
121
+ return "coercive warmth"
122
 
123
+ # 3. Cold Invalidation
124
+ if (neutral + disgust) > 0.5 \
125
+ and lex_counts["disgust"] > 0 \
126
  and any(p in patterns for p in ["dismissiveness","projection","obscure language"]):
127
+ return "cold invalidation"
128
 
129
+ # 4. Genuine Vulnerability
130
+ if (sadness + fear) > 0.5 \
131
+ and lex_counts["sadness"] > 0 and lex_counts["fear"] > 0 \
132
  and all(p == "recovery phase" for p in patterns):
133
+ return "genuine vulnerability"
134
 
135
+ # 5. Emotional Threat
136
+ if (anger + disgust) > 0.5 \
137
+ and (lex_counts["anger"] > 0 or lex_counts["disgust"] > 0) \
138
  and any(p in patterns for p in ["control","threat","insults","dismissiveness"]):
139
+ return "emotional threat"
140
 
141
+ # 6. Weaponized Sadness
142
+ if sadness > 0.6 \
143
+ and lex_counts["sadness"] > 0 \
144
  and any(p in patterns for p in ["guilt tripping","projection"]):
145
+ return "weaponized sadness"
146
 
147
+ # 7. Toxic Resignation
148
+ if neutral > 0.5 \
149
+ and any(p in patterns for p in ["dismissiveness","obscure language"]) \
150
+ and lex_counts["disgust"] == 0:
151
+ return "toxic resignation"
152
 
153
+ # 8. Indignant Reproach
154
+ if anger > 0.5 \
155
+ and lex_counts["anger"] > 0 \
156
  and any(p in patterns for p in ["guilt tripping","contradictory statements"]):
157
+ return "indignant reproach"
158
+
159
+ # 9. Confrontational
160
+ if anger > 0.6 \
161
+ and lex_counts["anger"] > 0 \
162
+ and patterns:
163
+ return "confrontational"
164
+
165
+ # 10. Passive Aggression
166
+ if neutral > 0.6 \
167
+ and lex_counts["disgust"] > 0 \
168
+ and any(p in patterns for p in ["dismissiveness","projection"]):
169
+ return "passive aggression"
170
+
171
+ # 11. Sarcastic Mockery
172
+ if joy > 0.3 \
173
+ and lex_counts["joy"] > 0 \
174
+ and "insults" in patterns:
175
+ return "sarcastic mockery"
176
+
177
+ # 12. Menacing Threat
178
+ if fear > 0.3 \
179
+ and lex_counts["fear"] > 0 \
180
+ and "threat" in patterns:
181
+ return "menacing threat"
182
+
183
+ # 13. Pleading Concern
184
+ if sadness > 0.3 \
185
+ and lex_counts["sadness"] > 0 \
186
  and any(k in text_lower for k in APOLOGY_KEYWORDS) \
187
  and not patterns:
188
+ return "pleading concern"
189
 
190
+ # 14. Fear-mongering
191
+ if (fear + disgust) > 0.5 \
192
+ and lex_counts["fear"] > 0 \
193
  and "projection" in patterns:
194
+ return "fear-mongering"
195
 
196
+ # 15. Disbelieving Accusation
197
+ if surprise > 0.3 \
198
+ and lex_counts["surprise"] > 0 \
199
  and "blame shifting" in patterns:
200
+ return "disbelieving accusation"
201
 
202
+ # 16. Empathetic Solidarity
203
+ if joy > 0.2 and sadness > 0.2 \
204
+ and lex_counts["joy"] > 0 and lex_counts["sadness"] > 0 \
205
  and not patterns:
206
+ return "empathetic solidarity"
207
+
208
+ # 17. Assertive Boundary
209
+ if anger > 0.4 \
210
+ and lex_counts["anger"] > 0 \
211
+ and "control" in patterns:
212
+ return "assertive boundary"
213
+
214
+ # 18. Stonewalling
215
+ if neutral > 0.7 \
216
+ and lex_counts["disgust"] == 0 \
217
+ and not patterns:
218
+ return "stonewalling"
219
 
220
  return None
221