SamanthaStorm commited on
Commit
83af1fa
·
verified ·
1 Parent(s): 68f445c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -9,11 +9,15 @@ import io
9
  from PIL import Image
10
  from datetime import datetime
11
  from transformers import pipeline as hf_pipeline # prevent name collision with gradio pipeline
12
- def get_emotion_profile(text):
13
- emotions = emotion_pipeline(text)
14
- if isinstance(emotions, list) and isinstance(emotions[0], list):
15
- emotions = emotions[0]
16
- return {e['label'].lower(): round(e['score'], 3) for e in emotions}
 
 
 
 
17
  # Emotion model (no retraining needed)
18
  emotion_pipeline = hf_pipeline(
19
  "text-classification",
@@ -131,13 +135,15 @@ ESCALATION_QUESTIONS = [
131
  ]
132
 
133
 
134
- def get_emotional_tone_tag(emotions, sentiment, patterns, abuse_score, text):
135
- sadness = emotions.get("sadness", 0)
136
- joy = emotions.get("joy", 0)
137
- neutral = emotions.get("neutral", 0)
138
- disgust = emotions.get("disgust", 0)
139
- anger = emotions.get("anger", 0)
140
- fear = emotions.get("fear", 0)
 
 
141
  # 1. Performative Regret
142
  if (
143
  sadness > 0.4 and
@@ -453,7 +459,7 @@ def analyze_single_message(text, thresholds):
453
  label for label, score in zip(LABELS, scores)
454
  if score > adjusted_thresholds[label]
455
  ]
456
- tone_tag = get_emotional_tone_tag(emotion_profile, sentiment, threshold_labels, 0, text)
457
 
458
 
459
  top_patterns = sorted(
 
9
  from PIL import Image
10
  from datetime import datetime
11
  from transformers import pipeline as hf_pipeline # prevent name collision with gradio pipeline
12
+ def get_emotional_tone_tag(emotion_profile, sentiment, patterns, abuse_score, text):
13
+ sadness = emotion_profile.get("sadness", 0)
14
+ joy = emotion_profile.get("joy", 0)
15
+ neutral = emotion_profile.get("neutral", 0)
16
+ disgust = emotion_profile.get("disgust", 0)
17
+ anger = emotion_profile.get("anger", 0)
18
+ fear = emotion_profile.get("fear", 0)
19
+
20
+ # [then all the logic for performative regret → hostile moralizing]
21
  # Emotion model (no retraining needed)
22
  emotion_pipeline = hf_pipeline(
23
  "text-classification",
 
135
  ]
136
 
137
 
138
+ def get_emotional_tone_tag(emotion_profile, sentiment, patterns, abuse_score, text):
139
+ sadness = emotion_profile.get("sadness", 0)
140
+ joy = emotion_profile.get("joy", 0)
141
+ neutral = emotion_profile.get("neutral", 0)
142
+ disgust = emotion_profile.get("disgust", 0)
143
+ anger = emotion_profile.get("anger", 0)
144
+ fear = emotion_profile.get("fear", 0)
145
+
146
+ # [then all the logic for performative regret → hostile moralizing]
147
  # 1. Performative Regret
148
  if (
149
  sadness > 0.4 and
 
459
  label for label, score in zip(LABELS, scores)
460
  if score > adjusted_thresholds[label]
461
  ]
462
+ tone_tag = get_emotional_tone_tag(emotion_profile, sentiment, threshold_labels, abuse_score, text)
463
 
464
 
465
  top_patterns = sorted(