Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -155,31 +155,37 @@ st.write("selected_images info:", selected_images)
|
|
155 |
st.write("selected_file_names info:", selected_file_names)
|
156 |
st.write("results info:", results)
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
#
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
# Create DataFrame
|
181 |
-
df = pd.DataFrame(df_data)
|
182 |
-
|
183 |
-
# Display DataFrame
|
184 |
-
st.write(df)
|
185 |
-
|
|
|
155 |
st.write("selected_file_names info:", selected_file_names)
|
156 |
st.write("results info:", results)
|
157 |
|
158 |
+
# Generate DataFrame from results
|
159 |
+
if st.button("Generate DataFrame") and results:
|
160 |
+
# Initialize an empty dictionary to store the scores
|
161 |
+
emotion_scores = {
|
162 |
+
'Neutral': [],
|
163 |
+
'Happy': [],
|
164 |
+
'Surprise': [],
|
165 |
+
'Disgust': [],
|
166 |
+
'Angry': [],
|
167 |
+
'Sad': [], # Add this if you have 'sad' scores in your results
|
168 |
+
'Fear': [] # Add this if you have 'fear' scores in your results
|
169 |
+
}
|
170 |
|
171 |
+
# Iterate over the results and populate the dictionary
|
172 |
+
for result_set in results:
|
173 |
+
for result in result_set:
|
174 |
+
# Capitalize the label and add the score to the corresponding list
|
175 |
+
emotion = result['label'].capitalize()
|
176 |
+
score = result['score']
|
177 |
+
if emotion in emotion_scores:
|
178 |
+
emotion_scores[emotion].append(score)
|
179 |
+
else:
|
180 |
+
# If the emotion is not in the dictionary, initialize a new list
|
181 |
+
emotion_scores[emotion] = [score]
|
182 |
+
|
183 |
+
# Convert the dictionary into a pandas DataFrame
|
184 |
+
df_emotions = pd.DataFrame(emotion_scores)
|
185 |
+
|
186 |
+
# Display the DataFrame
|
187 |
+
st.write(df_emotions)
|
188 |
+
|
189 |
+
# Optional: Save the DataFrame to a CSV file
|
190 |
+
df_emotions.to_csv('emotion_scores.csv', index=False)
|
191 |
+
st.success('DataFrame generated and saved as emotion_scores.csv')
|
|
|
|
|
|
|
|
|
|
|
|