Spaces:
Sleeping
Sleeping
felix.wf
commited on
Commit
·
9c81fd8
1
Parent(s):
5a6a4e1
modify image process
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ if file_name is not None:
|
|
48 |
|
49 |
# Calculate the number of rows needed for 3 columns
|
50 |
num_images = len(persons)
|
51 |
-
num_cols =
|
52 |
num_rows = (num_images + num_cols - 1) // num_cols # Ceiling division
|
53 |
|
54 |
# Create a new canvas to stitch all person images in a grid with 3 columns
|
@@ -107,19 +107,45 @@ if file_name is not None:
|
|
107 |
labels = list(label_counts.keys())
|
108 |
sizes = list(label_counts.values())
|
109 |
|
110 |
-
pie_fig,
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
# plt.show()
|
115 |
# Use Streamlit columns to display the images and pie chart side by side
|
116 |
-
|
117 |
|
118 |
-
with
|
119 |
st.pyplot(fig) # Display the stitched person images
|
120 |
|
121 |
-
with
|
122 |
st.pyplot(pie_fig) # Display the pie chart
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
elif file_name.type.startswith('video'):
|
125 |
# Save the uploaded video to a temporary file
|
|
|
48 |
|
49 |
# Calculate the number of rows needed for 3 columns
|
50 |
num_images = len(persons)
|
51 |
+
num_cols = 8
|
52 |
num_rows = (num_images + num_cols - 1) // num_cols # Ceiling division
|
53 |
|
54 |
# Create a new canvas to stitch all person images in a grid with 3 columns
|
|
|
107 |
labels = list(label_counts.keys())
|
108 |
sizes = list(label_counts.values())
|
109 |
|
110 |
+
pie_fig, pie_ax = plt.subplots()
|
111 |
+
pie_ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)
|
112 |
+
pie_ax.set_title('Distribution of Emotions')
|
113 |
+
pie_ax.axis('equal') # 确保饼状图为圆形
|
114 |
+
|
115 |
+
|
116 |
+
labels_refined = [item['label'] for item in output_list_emotions_refined]
|
117 |
+
label_counts_refined = {label: labels_refined.count(label) for label in set(labels_refined)}
|
118 |
+
|
119 |
+
bar_fig, bar_ax = plt.subplots()
|
120 |
+
bar_ax.bar(label_counts_refined.keys(), label_counts_refined.values())
|
121 |
+
bar_ax.set_title('Distribution of Emotions')
|
122 |
+
bar_ax.set_xlabel('Emotions')
|
123 |
+
bar_ax.set_ylabel('Count')
|
124 |
+
|
125 |
+
labels_emotions = [item['label'] for item in output_list_emotions]
|
126 |
+
label_counts_emotions = {label: labels_emotions.count(label) for label in set(labels_emotions)}
|
127 |
+
|
128 |
+
bar_fig_emotions, bar_ax_emotions = plt.subplots()
|
129 |
+
bar_ax_emotions.bar(label_counts_emotions.keys(), label_counts_emotions.values())
|
130 |
+
bar_ax_emotions.set_title('Distribution of Emotions')
|
131 |
+
bar_ax_emotions.set_xlabel('Emotions')
|
132 |
+
bar_ax_emotions.set_ylabel('Count')
|
133 |
+
|
134 |
# plt.show()
|
135 |
# Use Streamlit columns to display the images and pie chart side by side
|
136 |
+
row1, row2, row3, row4 = st.rows(4)
|
137 |
|
138 |
+
with row1:
|
139 |
st.pyplot(fig) # Display the stitched person images
|
140 |
|
141 |
+
with row2:
|
142 |
st.pyplot(pie_fig) # Display the pie chart
|
143 |
+
|
144 |
+
with row3:
|
145 |
+
st.pyplot(bar_fig) # Display the bar chart
|
146 |
+
|
147 |
+
with row4:
|
148 |
+
st.pyplot(bar_fig_emotions) # Display the bar chart
|
149 |
|
150 |
elif file_name.type.startswith('video'):
|
151 |
# Save the uploaded video to a temporary file
|