xtlyxt commited on
Commit
3d38f3e
·
verified ·
1 Parent(s): 8f9b3cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -133,3 +133,40 @@ if st.button("Predict Emotions") and selected_images:
133
  ax_bar.text(i.get_x() + i.get_width() / 2, i.get_height() + 0.1, int(i.get_height()), ha='center', va='bottom')
134
 
135
  st.pyplot(fig_bar)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  ax_bar.text(i.get_x() + i.get_width() / 2, i.get_height() + 0.1, int(i.get_height()), ha='center', va='bottom')
134
 
135
  st.pyplot(fig_bar)
136
+
137
+
138
+ # Generate DataFrame button
139
+ if st.button("Generate DataFrame") and selected_images:
140
+ # Create a list to store data for DataFrame
141
+ df_data = []
142
+
143
+ # Iterate through selected images to gather data
144
+ for image, file_name, result in zip(selected_images, selected_file_names, results):
145
+ # Extract image metadata
146
+ size_kb = image.size[0] * image.size[1] / 1024.0 # Calculating size in KB
147
+ timestamp = datetime.datetime.now() # Current timestamp
148
+ color_type = "Color" if len(image.getbands()) > 1 else "Grayscale"
149
+
150
+ # Extract predicted emotions and scores
151
+ emotion_scores = {res["label"].split("_")[-1].capitalize(): res["score"] for res in result}
152
+
153
+ # Append image metadata and emotion scores to the list
154
+ df_data.append({
155
+ "Neutral": f"{emotion_scores.get('Neutral', 0.0):.4f}",
156
+ "Happy": f"{emotion_scores.get('Happy', 0.0):.4f}",
157
+ "Sad": f"{emotion_scores.get('Sad', 0.0):.4f}",
158
+ "Angry": f"{emotion_scores.get('Angry', 0.0):.4f}",
159
+ "Disgust": f"{emotion_scores.get('Disgust', 0.0):.4f}",
160
+ "Surprise": f"{emotion_scores.get('Surprise', 0.0):.4f}",
161
+ "Fear": f"{emotion_scores.get('Fear', 0.0):.4f}",
162
+ "File Name": file_name,
163
+ "Size (KB)": size_kb,
164
+ "Timestamp": timestamp,
165
+ "Color Type": color_type
166
+ })
167
+
168
+ # Create DataFrame
169
+ df = pd.DataFrame(df_data)
170
+
171
+ # Display DataFrame
172
+ st.write(df)