SamanthaStorm commited on
Commit
c96a489
·
verified ·
1 Parent(s): f82bb8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -36
app.py CHANGED
@@ -37,43 +37,64 @@ THRESHOLDS = {
37
  "projection": 0.09, "recovery phase": 0.33, "threat": 0.15
38
  }
39
 
40
-
41
- # ——— 3) Emotional-tone tagging (no abuse_score / DARVO) —————————————————————————————
42
  def get_emotional_tone_tag(emotion_profile, patterns):
43
- anger = emotion_profile.get("anger", 0)
44
- disgust = emotion_profile.get("disgust", 0)
45
  sadness = emotion_profile.get("sadness", 0)
46
  joy = emotion_profile.get("joy", 0)
47
  neutral = emotion_profile.get("neutral", 0)
 
 
48
  fear = emotion_profile.get("fear", 0)
49
 
50
- # 1) Vulnerable: sadness high + recovery-phase
51
- if sadness > 0.4 and "recovery phase" in patterns:
52
- return "vulnerable"
53
-
54
- # 2) Supportive: joy very high + no other patterns (or only recovery-phase)
55
- if joy > 0.5 and (not patterns or patterns == ["recovery phase"]):
56
- return "supportive"
57
-
58
- # 3) Confrontational: anger/disgust high + aggressive patterns
59
- if (anger + disgust) > 0.5 and any(p in patterns for p in ["insults", "control", "threat"]):
60
- return "confrontational"
61
-
62
- # 4) Manipulative: neutral high + manipulation patterns
63
- if neutral > 0.4 and any(p in patterns for p in ["gaslighting", "dismissiveness", "projection", "guilt tripping", "blame shifting"]):
64
- return "manipulative"
65
-
66
- # 5) Feigned Warmth: joy high but manipulative patterns present
67
- if joy > 0.5 and any(p in patterns for p in ["gaslighting", "dismissiveness", "projection", "guilt tripping", "blame shifting"]):
68
- return "feigned warmth"
69
-
70
- # 6) Defensive: anger high + contradictory statements
71
- if anger > 0.4 and "contradictory statements" in patterns:
72
- return "defensive"
73
-
74
- # 7) Neutral: pure neutral dominates all
75
- if neutral > max(anger, disgust, sadness, joy, fear):
76
- return "neutral"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  return None
79
 
@@ -95,7 +116,13 @@ def analyze_message(text):
95
  if prob >= THRESHOLDS[label]
96
  ]
97
 
98
- # 4) tone tagging
 
 
 
 
 
 
99
  tone_tag = get_emotional_tone_tag(emotion_profile, active_patterns)
100
 
101
  return {
@@ -105,7 +132,7 @@ def analyze_message(text):
105
  }
106
 
107
 
108
- # ——— 5) Composite wrapper (handles .txt or image + text boxes) ——————————————————————
109
  def analyze_composite(uploaded_file, *texts):
110
  outputs = []
111
 
@@ -153,10 +180,12 @@ message_inputs = [gr.Textbox(label=f"Message {i+1}") for i in range(3)]
153
 
154
  iface = gr.Interface(
155
  fn=analyze_composite,
156
- inputs=[gr.File(file_types=[".txt", ".png", ".jpg", ".jpeg"], label="Upload text or image")] + message_inputs,
 
 
157
  outputs=gr.Textbox(label="Analysis"),
158
- title="Tether Analyzer (streamlined)",
159
- description="Emotion profiling, pattern tags, and tone tagging—no motif detection, no abuse score or DARVO."
160
  )
161
 
162
  if __name__ == "__main__":
 
37
  "projection": 0.09, "recovery phase": 0.33, "threat": 0.15
38
  }
39
 
40
+ # ——— 3) Emotional-tone tagging (detailed categories) —————————————————————————————
 
41
  def get_emotional_tone_tag(emotion_profile, patterns):
42
+ # unpack emotion scores
 
43
  sadness = emotion_profile.get("sadness", 0)
44
  joy = emotion_profile.get("joy", 0)
45
  neutral = emotion_profile.get("neutral", 0)
46
+ disgust = emotion_profile.get("disgust", 0)
47
+ anger = emotion_profile.get("anger", 0)
48
  fear = emotion_profile.get("fear", 0)
49
 
50
+ # 1. Performative Regret
51
+ if (
52
+ sadness > 0.4 and
53
+ any(p in patterns for p in ["blame shifting", "guilt tripping", "recovery phase"])
54
+ ):
55
+ return "performative regret"
56
+
57
+ # 2. Coercive Warmth
58
+ if (
59
+ (joy > 0.3 or sadness > 0.4) and
60
+ any(p in patterns for p in ["control", "gaslighting"])
61
+ ):
62
+ return "coercive warmth"
63
+
64
+ # 3. Cold Invalidation
65
+ if (
66
+ (neutral + disgust) > 0.5 and
67
+ any(p in patterns for p in ["dismissiveness", "projection", "obscure language"])
68
+ ):
69
+ return "cold invalidation"
70
+
71
+ # 4. Genuine Vulnerability
72
+ if (
73
+ (sadness + fear) > 0.5 and
74
+ all(p == "recovery phase" for p in patterns)
75
+ ):
76
+ return "genuine vulnerability"
77
+
78
+ # 5. Emotional Threat
79
+ if (
80
+ (anger + disgust) > 0.5 and
81
+ any(p in patterns for p in ["control", "threat", "insults", "dismissiveness"])
82
+ ):
83
+ return "emotional threat"
84
+
85
+ # 6. Weaponized Sadness
86
+ if (
87
+ sadness > 0.6 and
88
+ any(p in patterns for p in ["guilt tripping", "projection"])
89
+ ):
90
+ return "weaponized sadness"
91
+
92
+ # 7. Toxic Resignation
93
+ if (
94
+ neutral > 0.5 and
95
+ any(p in patterns for p in ["dismissiveness", "obscure language"])
96
+ ):
97
+ return "toxic resignation"
98
 
99
  return None
100
 
 
116
  if prob >= THRESHOLDS[label]
117
  ]
118
 
119
+ # 4) add recovery-phase on apology keywords
120
+ low = text.lower()
121
+ if any(k in low for k in ["sorry", "apolog", "forgive"]):
122
+ if "recovery phase" not in active_patterns:
123
+ active_patterns.append("recovery phase")
124
+
125
+ # 5) tone tagging with detailed rules
126
  tone_tag = get_emotional_tone_tag(emotion_profile, active_patterns)
127
 
128
  return {
 
132
  }
133
 
134
 
135
+ # ——— 5) Composite wrapper (handles uploads + text boxes) ——————————————————————————
136
  def analyze_composite(uploaded_file, *texts):
137
  outputs = []
138
 
 
180
 
181
  iface = gr.Interface(
182
  fn=analyze_composite,
183
+ inputs=[
184
+ gr.File(file_types=[".txt", ".png", ".jpg", ".jpeg"], label="Upload text or image")
185
+ ] + message_inputs,
186
  outputs=gr.Textbox(label="Analysis"),
187
+ title="Tether Analyzer (detailed tone tags)",
188
+ description="Emotion profiling, pattern tags, and nuanced tone categories—no abuse score or DARVO."
189
  )
190
 
191
  if __name__ == "__main__":