de-Rodrigo commited on
Commit
f80e37d
·
1 Parent(s): a254745

Download Button for Reduced Space

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -16,7 +16,8 @@ import json
16
  import itertools
17
  import matplotlib.pyplot as plt
18
  import matplotlib.colors as mcolors
19
-
 
20
 
21
 
22
  N_COMPONENTS = 3
@@ -1286,6 +1287,30 @@ def run_model(model_name):
1286
  # Mostrar el heatmap en la app
1287
  st.bokeh_chart(heatmap_fig)
1288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1289
 
1290
  def main():
1291
  config_style()
 
16
  import itertools
17
  import matplotlib.pyplot as plt
18
  import matplotlib.colors as mcolors
19
+ import zipfile
20
+ import tempfile
21
 
22
 
23
  N_COMPONENTS = 3
 
1287
  # Mostrar el heatmap en la app
1288
  st.bokeh_chart(heatmap_fig)
1289
 
1290
+ # Botón para descargar df_all (Embeddings in PCA Space)
1291
+ if st.button("Download Embeddings in PCA Space", key=f"click_download_pca_coordinates_{model_name}"):
1292
+ # Crear un nuevo diccionario con solo las columnas que comienzan con "PC"
1293
+ df_all_pca = {}
1294
+ for key, df in df_all.items():
1295
+ pca_cols = [col for col in df.columns if col.startswith("PC")]
1296
+ df_all_pca[key] = df[pca_cols].copy()
1297
+
1298
+ # Crear un buffer en memoria para el archivo Excel
1299
+ excel_buffer = io.BytesIO()
1300
+ # Escribir cada DataFrame (solo con columnas PCA) en una hoja separada
1301
+ with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer:
1302
+ for key_name, df in df_all_pca.items():
1303
+ df.to_excel(writer, sheet_name=key_name, index=False)
1304
+ excel_buffer.seek(0)
1305
+
1306
+ st.download_button(
1307
+ label="Download Embeddings in PCA Space",
1308
+ data=excel_buffer,
1309
+ file_name=f"df_all_pca_{model_name.lower()}.xlsx",
1310
+ mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1311
+ key=f"download_pca_coordinates_{model_name}"
1312
+ )
1313
+
1314
 
1315
  def main():
1316
  config_style()