Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -112,33 +112,34 @@ if st.button("Generate HeatMap & DataFrame"):
|
|
112 |
mime='text/csv',
|
113 |
)
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
112 |
mime='text/csv',
|
113 |
)
|
114 |
|
115 |
+
# Save the DataFrame to an Excel file with images
|
116 |
+
if st.button("Save to Excel"):
|
117 |
+
# Create a new Excel writer object
|
118 |
+
writer = pd.ExcelWriter('emotion_scores.xlsx', engine='xlsxwriter')
|
119 |
+
df_emotions.to_excel(writer, index=False)
|
120 |
+
|
121 |
+
# Access the xlsxwriter workbook and worksheet objects
|
122 |
+
workbook = writer.book
|
123 |
+
worksheet = writer.sheets['Sheet1']
|
124 |
+
|
125 |
+
# Iterate over the images and insert them into the 'Image View' column
|
126 |
+
for idx, image_path in enumerate(st.session_state['image_names']):
|
127 |
+
# Your logic to define the image_path
|
128 |
+
worksheet.insert_image(f'J{idx + 2}', image_path) # 'J' is the 10th column
|
129 |
+
|
130 |
+
# Close the writer and save the Excel file
|
131 |
+
writer.save()
|
132 |
+
st.session_state['excel_saved'] = True
|
133 |
+
st.success('DataFrame generated and saved as emotion_scores.xlsx')
|
134 |
+
|
135 |
+
# Check if the Excel file was saved and provide a download button
|
136 |
+
if st.session_state.get('excel_saved', False):
|
137 |
+
with open('emotion_scores.xlsx', 'rb') as f:
|
138 |
+
excel_file = f.read()
|
139 |
+
|
140 |
+
st.download_button(
|
141 |
+
label='Download Emotion Scores as Excel',
|
142 |
+
data=excel_file,
|
143 |
+
file_name='emotion_scores.xlsx',
|
144 |
+
mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
145 |
+
)
|