Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -196,16 +196,38 @@ THREAT_MOTIFS = [
|
|
196 |
def get_emotion_profile(text):
|
197 |
"""Get emotion profile from text with all scores"""
|
198 |
try:
|
|
|
|
|
|
|
199 |
emotions = emotion_pipeline(text)
|
|
|
|
|
200 |
if isinstance(emotions, list) and isinstance(emotions[0], list):
|
201 |
# Extract all scores from the first prediction
|
202 |
emotion_scores = emotions[0]
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
return {}
|
|
|
206 |
except Exception as e:
|
207 |
logger.error(f"Error in get_emotion_profile: {e}")
|
208 |
-
|
|
|
209 |
"sadness": 0.0,
|
210 |
"joy": 0.0,
|
211 |
"neutral": 0.0,
|
@@ -213,6 +235,9 @@ def get_emotion_profile(text):
|
|
213 |
"anger": 0.0,
|
214 |
"fear": 0.0
|
215 |
}
|
|
|
|
|
|
|
216 |
|
217 |
def get_emotional_tone_tag(text, sentiment, patterns, abuse_score):
|
218 |
"""Get emotional tone tag based on emotions and patterns"""
|
|
|
196 |
def get_emotion_profile(text):
|
197 |
"""Get emotion profile from text with all scores"""
|
198 |
try:
|
199 |
+
logger.debug("\n🎭 EMOTION ANALYSIS")
|
200 |
+
logger.debug(f"Analyzing text: {text}")
|
201 |
+
|
202 |
emotions = emotion_pipeline(text)
|
203 |
+
logger.debug(f"Raw emotion pipeline output: {emotions}")
|
204 |
+
|
205 |
if isinstance(emotions, list) and isinstance(emotions[0], list):
|
206 |
# Extract all scores from the first prediction
|
207 |
emotion_scores = emotions[0]
|
208 |
+
|
209 |
+
# Log raw scores
|
210 |
+
logger.debug("\nRaw emotion scores:")
|
211 |
+
for e in emotion_scores:
|
212 |
+
logger.debug(f" • {e['label']}: {e['score']:.3f}")
|
213 |
+
|
214 |
+
# Convert to dictionary
|
215 |
+
emotion_dict = {e['label'].lower(): round(e['score'], 3) for e in emotion_scores}
|
216 |
+
|
217 |
+
# Log final processed emotions
|
218 |
+
logger.debug("\nProcessed emotion profile:")
|
219 |
+
for emotion, score in emotion_dict.items():
|
220 |
+
logger.debug(f" • {emotion}: {score:.3f}")
|
221 |
+
|
222 |
+
return emotion_dict
|
223 |
+
|
224 |
+
logger.debug("No valid emotions detected, returning empty dict")
|
225 |
return {}
|
226 |
+
|
227 |
except Exception as e:
|
228 |
logger.error(f"Error in get_emotion_profile: {e}")
|
229 |
+
logger.error(f"Traceback: {traceback.format_exc()}")
|
230 |
+
default_emotions = {
|
231 |
"sadness": 0.0,
|
232 |
"joy": 0.0,
|
233 |
"neutral": 0.0,
|
|
|
235 |
"anger": 0.0,
|
236 |
"fear": 0.0
|
237 |
}
|
238 |
+
logger.debug(f"Returning default emotions: {default_emotions}")
|
239 |
+
return default_emotions
|
240 |
+
|
241 |
|
242 |
def get_emotional_tone_tag(text, sentiment, patterns, abuse_score):
|
243 |
"""Get emotional tone tag based on emotions and patterns"""
|