Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -143,41 +143,36 @@ if st.button("Predict Emotions") and selected_images:
|
|
143 |
|
144 |
# Generate DataFrame button
|
145 |
if st.button("Generate DataFrame") and selected_images:
|
146 |
-
#
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
df = pd.DataFrame(df_data)
|
180 |
-
|
181 |
-
# Display DataFrame
|
182 |
-
st.write(df)
|
183 |
-
|
|
|
143 |
|
144 |
# Generate DataFrame button
|
145 |
if st.button("Generate DataFrame") and selected_images:
|
146 |
+
# Create a list to store data for DataFrame
|
147 |
+
df_data = []
|
148 |
+
|
149 |
+
# Iterate through selected images to gather data
|
150 |
+
for image, file_name, result in zip(selected_images, selected_file_names, results):
|
151 |
+
# Extract image metadata
|
152 |
+
size_kb = image.size[0] * image.size[1] / 1024.0 # Calculating size in KB
|
153 |
+
timestamp = datetime.datetime.now() # Current timestamp
|
154 |
+
color_type = "Color" if len(image.getbands()) > 1 else "Grayscale"
|
155 |
+
|
156 |
+
# Extract predicted emotions and scores
|
157 |
+
emotion_scores = {res["label"].split("_")[-1].capitalize(): res["score"] for res in result}
|
158 |
+
|
159 |
+
# Append image metadata and emotion scores to the list
|
160 |
+
df_data.append({
|
161 |
+
"Neutral": f"{emotion_scores.get('Neutral', 0.0):.4f}",
|
162 |
+
"Happy": f"{emotion_scores.get('Happy', 0.0):.4f}",
|
163 |
+
"Sad": f"{emotion_scores.get('Sad', 0.0):.4f}",
|
164 |
+
"Angry": f"{emotion_scores.get('Angry', 0.0):.4f}",
|
165 |
+
"Disgust": f"{emotion_scores.get('Disgust', 0.0):.4f}",
|
166 |
+
"Surprise": f"{emotion_scores.get('Surprise', 0.0):.4f}",
|
167 |
+
"Fear": f"{emotion_scores.get('Fear', 0.0):.4f}",
|
168 |
+
"File Name": file_name,
|
169 |
+
"Size (KB)": size_kb,
|
170 |
+
"Timestamp": timestamp,
|
171 |
+
"Color Type": color_type
|
172 |
+
})
|
173 |
+
|
174 |
+
# Create DataFrame
|
175 |
+
df = pd.DataFrame(df_data)
|
176 |
+
|
177 |
+
# Display DataFrame
|
178 |
+
st.write(df)
|
|
|
|
|
|
|
|
|
|