Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -74,17 +74,32 @@ if st.button("Predict Emotions") and selected_images:
|
|
74 |
# Calculate emotion statistics
|
75 |
emotion_counts = pd.Series(emotions).value_counts()
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Plot pie chart
|
78 |
st.write("Emotion Distribution (Pie Chart):")
|
79 |
fig_pie, ax_pie = plt.subplots()
|
80 |
-
ax_pie.pie(emotion_counts, labels=emotion_counts.index, autopct='%1.1f%%', startangle=140, colors=
|
81 |
ax_pie.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
|
82 |
st.pyplot(fig_pie)
|
83 |
|
|
|
|
|
|
|
84 |
# Plot bar chart
|
85 |
st.write("Emotion Distribution (Bar Chart):")
|
86 |
fig_bar, ax_bar = plt.subplots()
|
87 |
-
emotion_counts.plot(kind='bar', color=
|
88 |
ax_bar.set_xlabel('Emotion')
|
89 |
ax_bar.set_ylabel('Count')
|
90 |
ax_bar.set_title('Emotion Distribution')
|
|
|
74 |
# Calculate emotion statistics
|
75 |
emotion_counts = pd.Series(emotions).value_counts()
|
76 |
|
77 |
+
# Define a color map that matches the emotions to specific colors
|
78 |
+
color_map = {
|
79 |
+
'Happy': '#ff9999',
|
80 |
+
'Sad': '#66b3ff',
|
81 |
+
'Angry': '#99ff99',
|
82 |
+
'Surprised': '#ffcc99'
|
83 |
+
# Add more emotions and their corresponding colors here
|
84 |
+
}
|
85 |
+
|
86 |
+
# Use the color map to assign colors to the pie chart
|
87 |
+
pie_colors = [color_map.get(emotion, '#999999') for emotion in emotion_counts.index] # Default to grey if not found
|
88 |
+
|
89 |
# Plot pie chart
|
90 |
st.write("Emotion Distribution (Pie Chart):")
|
91 |
fig_pie, ax_pie = plt.subplots()
|
92 |
+
ax_pie.pie(emotion_counts, labels=emotion_counts.index, autopct='%1.1f%%', startangle=140, colors=pie_colors)
|
93 |
ax_pie.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
|
94 |
st.pyplot(fig_pie)
|
95 |
|
96 |
+
# Use the same color map for the bar chart
|
97 |
+
bar_colors = [color_map.get(emotion, '#999999') for emotion in emotion_counts.index] # Default to grey if not found
|
98 |
+
|
99 |
# Plot bar chart
|
100 |
st.write("Emotion Distribution (Bar Chart):")
|
101 |
fig_bar, ax_bar = plt.subplots()
|
102 |
+
emotion_counts.plot(kind='bar', color=bar_colors, ax=ax_bar)
|
103 |
ax_bar.set_xlabel('Emotion')
|
104 |
ax_bar.set_ylabel('Count')
|
105 |
ax_bar.set_title('Emotion Distribution')
|