MaroofTechSorcerer commited on
Commit
b2e2b24
Β·
verified Β·
1 Parent(s): a517da1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -67,10 +67,12 @@ def perform_emotion_detection(text):
67
 
68
  emotion_results = emotion_classifier(text)
69
  print(f"Raw emotion classifier output: {emotion_results}")
70
- if not emotion_results or not isinstance(emotion_results, list):
71
- st.error("Emotion classifier returned invalid results.")
72
  return {}, "neutral", {}, "NEUTRAL"
73
 
 
 
74
  emotion_map = {
75
  "joy": "😊", "anger": "😑", "disgust": "🀒", "fear": "😨",
76
  "sadness": "😭", "surprise": "😲"
@@ -81,7 +83,14 @@ def perform_emotion_detection(text):
81
 
82
  emotions_dict = {}
83
  for result in emotion_results:
84
- emotions_dict[result['label']] = result['score']
 
 
 
 
 
 
 
85
 
86
  filtered_emotions = {k: v for k, v in emotions_dict.items() if v > 0.01}
87
 
 
67
 
68
  emotion_results = emotion_classifier(text)
69
  print(f"Raw emotion classifier output: {emotion_results}")
70
+ if not emotion_results or not isinstance(emotion_results, list) or not emotion_results[0]:
71
+ st.error("Emotion classifier returned invalid or empty results.")
72
  return {}, "neutral", {}, "NEUTRAL"
73
 
74
+ # Access the first inner list, which contains the emotion dictionaries
75
+ emotion_results = emotion_results[0]
76
  emotion_map = {
77
  "joy": "😊", "anger": "😑", "disgust": "🀒", "fear": "😨",
78
  "sadness": "😭", "surprise": "😲"
 
83
 
84
  emotions_dict = {}
85
  for result in emotion_results:
86
+ if isinstance(result, dict) and 'label' in result and 'score' in result:
87
+ emotions_dict[result['label']] = result['score']
88
+ else:
89
+ print(f"Invalid result format: {result}")
90
+
91
+ if not emotions_dict:
92
+ st.error("No valid emotions detected.")
93
+ return {}, "neutral", {}, "NEUTRAL"
94
 
95
  filtered_emotions = {k: v for k, v in emotions_dict.items() if v > 0.01}
96