Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|