xtlyxt commited on
Commit
ead6b33
·
verified ·
1 Parent(s): 449534b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -112,33 +112,34 @@ if st.button("Generate HeatMap & DataFrame"):
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.success('DataFrame generated and saved as emotion_scores.xlsx')
133
-
134
- with open('emotion_scores.xlsx', 'rb') as f:
135
- excel_file = f.read()
136
-
137
- st.download_button(
138
- label='Download Emotion Scores as Excel',
139
- data=excel_file,
140
- file_name='emotion_scores.xlsx',
141
- mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
142
- )
143
- else:
144
- st.error("No results to generate DataFrame. Please predict emotions first.")
 
 
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
+ )