Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -154,9 +154,13 @@ else:
|
|
154 |
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 |
# 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': [],
|
@@ -164,21 +168,25 @@ if st.button("Generate DataFrame") and results:
|
|
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
|
175 |
emotion = result['label'].capitalize()
|
176 |
-
score = result['score']
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
|
183 |
# Convert the dictionary into a pandas DataFrame
|
184 |
df_emotions = pd.DataFrame(emotion_scores)
|
@@ -189,3 +197,4 @@ if st.button("Generate DataFrame") and results:
|
|
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')
|
|
|
|
154 |
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 |
# Generate DataFrame from results
|
161 |
if st.button("Generate DataFrame") and results:
|
162 |
+
st.write("results info inner loop:", results)
|
163 |
+
|
164 |
# Initialize an empty dictionary to store the scores
|
165 |
emotion_scores = {
|
166 |
'Neutral': [],
|
|
|
168 |
'Surprise': [],
|
169 |
'Disgust': [],
|
170 |
'Angry': [],
|
171 |
+
# Add other emotions if necessary
|
172 |
'Sad': [], # Add this if you have 'sad' scores in your results
|
173 |
'Fear': [] # Add this if you have 'fear' scores in your results
|
174 |
}
|
175 |
|
176 |
# Iterate over the results and populate the dictionary
|
177 |
for result_set in results:
|
178 |
+
# Initialize a dictionary for the current set with zeros
|
179 |
+
current_scores = {emotion: 0 for emotion in emotion_scores.keys()}
|
180 |
+
|
181 |
for result in result_set:
|
182 |
+
# Capitalize the label and update the score in the current set
|
183 |
emotion = result['label'].capitalize()
|
184 |
+
score = round(result['score'], 4) # Round the score to 4 decimal places
|
185 |
+
current_scores[emotion] = score
|
186 |
+
|
187 |
+
# Add the current scores to the emotion_scores dictionary
|
188 |
+
for emotion, score in current_scores.items():
|
189 |
+
emotion_scores[emotion].append(score)
|
190 |
|
191 |
# Convert the dictionary into a pandas DataFrame
|
192 |
df_emotions = pd.DataFrame(emotion_scores)
|
|
|
197 |
# Optional: Save the DataFrame to a CSV file
|
198 |
df_emotions.to_csv('emotion_scores.csv', index=False)
|
199 |
st.success('DataFrame generated and saved as emotion_scores.csv')
|
200 |
+
|