xtlyxt commited on
Commit
384bc42
·
verified ·
1 Parent(s): e116055

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -27
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
- # Generate DataFrame button
160
- if st.button("Generate DataFrame") and selected_images:
161
- # Create a list to store data for DataFrame
162
- df_data = []
163
-
164
- # Iterate through selected images to gather data
165
- for result in results:
166
- # Extract predicted emotions and scores
167
- emotion_scores = {res["label"].split("_")[-1].capitalize(): res["score"] for res in result}
168
-
169
- # Append emotion scores to the list
170
- df_data.append({
171
- "Neutral": f"{emotion_scores.get('Neutral', 0.0):.4f}",
172
- "Happy": f"{emotion_scores.get('Happy', 0.0):.4f}",
173
- "Sad": f"{emotion_scores.get('Sad', 0.0):.4f}",
174
- "Angry": f"{emotion_scores.get('Angry', 0.0):.4f}",
175
- "Disgust": f"{emotion_scores.get('Disgust', 0.0):.4f}",
176
- "Surprise": f"{emotion_scores.get('Surprise', 0.0):.4f}",
177
- "Fear": f"{emotion_scores.get('Fear', 0.0):.4f}" # Add this line if 'Fear' is a possible label
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')