Spaces:
Sleeping
Sleeping
Commit
路
2f91a8e
1
Parent(s):
f006319
Test Chromium
Browse files
app.py
CHANGED
|
@@ -16,6 +16,24 @@ import json
|
|
| 16 |
import itertools
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
import matplotlib.colors as mcolors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
N_COMPONENTS = 3
|
|
@@ -1166,6 +1184,10 @@ def run_model(model_name):
|
|
| 1166 |
x_bins = np.linspace(x_min, x_max, grid_size + 1)
|
| 1167 |
y_bins = np.linspace(y_min, y_max, grid_size + 1)
|
| 1168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1169 |
# Generar heatmaps para cada combinaci贸n de componentes
|
| 1170 |
pairs = list(itertools.combinations(range(N_COMPONENTS), 2))
|
| 1171 |
for (i, j) in pairs:
|
|
@@ -1202,7 +1224,7 @@ def run_model(model_name):
|
|
| 1202 |
# Transponer la matriz para alinear correctamente los ejes
|
| 1203 |
heatmap_data = heat_stat.T
|
| 1204 |
|
| 1205 |
-
# Definir el color mapper
|
| 1206 |
if selected_feature in model_options:
|
| 1207 |
color_mapper = LinearColorMapper(
|
| 1208 |
palette=red_green_palette,
|
|
@@ -1226,8 +1248,10 @@ def run_model(model_name):
|
|
| 1226 |
sizing_mode="fixed")
|
| 1227 |
heatmap_fig.match_aspect = True
|
| 1228 |
|
|
|
|
| 1229 |
heatmap_fig.xaxis.axis_label = x_comp
|
| 1230 |
heatmap_fig.yaxis.axis_label = y_comp
|
|
|
|
| 1231 |
# Dibujar la imagen del heatmap
|
| 1232 |
heatmap_fig.image(image=[heatmap_data], x=x_min, y=y_min,
|
| 1233 |
dw=x_max - x_min, dh=y_max - y_min,
|
|
@@ -1250,7 +1274,7 @@ def run_model(model_name):
|
|
| 1250 |
""")
|
| 1251 |
heatmap_fig.add_layout(color_bar, 'right')
|
| 1252 |
|
| 1253 |
-
# Agregar renderer invisible para tooltips
|
| 1254 |
source_points = ColumnDataSource(data={
|
| 1255 |
'x': df_heatmap['x'],
|
| 1256 |
'y': df_heatmap['y'],
|
|
@@ -1259,7 +1283,6 @@ def run_model(model_name):
|
|
| 1259 |
})
|
| 1260 |
invisible_renderer = heatmap_fig.circle('x', 'y', size=10, source=source_points, fill_alpha=0, line_alpha=0.5)
|
| 1261 |
|
| 1262 |
-
# Si se selecciona un dataset extra, proyectar sus puntos en la combinaci贸n actual
|
| 1263 |
if select_extra_dataset_hm != "-":
|
| 1264 |
df_extra = df_all["synthetic"][df_all["synthetic"]["source"] == select_extra_dataset_hm].copy()
|
| 1265 |
df_extra["x"] = df_extra[x_comp]
|
|
@@ -1277,7 +1300,42 @@ def run_model(model_name):
|
|
| 1277 |
hover_tool_points = HoverTool(renderers=[invisible_renderer], tooltips=TOOLTIPS)
|
| 1278 |
heatmap_fig.add_tools(hover_tool_points)
|
| 1279 |
|
|
|
|
| 1280 |
st.bokeh_chart(heatmap_fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1281 |
|
| 1282 |
def main():
|
| 1283 |
config_style()
|
|
|
|
| 16 |
import itertools
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
import matplotlib.colors as mcolors
|
| 19 |
+
import zipfile
|
| 20 |
+
import tempfile
|
| 21 |
+
import shutil
|
| 22 |
+
from selenium.webdriver.firefox.options import Options
|
| 23 |
+
from selenium.webdriver.firefox.service import Service
|
| 24 |
+
from selenium import webdriver
|
| 25 |
+
from bokeh.io import export_png
|
| 26 |
+
import os
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
from selenium import webdriver
|
| 30 |
+
from selenium.webdriver.firefox.service import Service as ChromeService
|
| 31 |
+
from selenium.webdriver.firefox.options import Options
|
| 32 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
|
| 38 |
|
| 39 |
N_COMPONENTS = 3
|
|
|
|
| 1184 |
x_bins = np.linspace(x_min, x_max, grid_size + 1)
|
| 1185 |
y_bins = np.linspace(y_min, y_max, grid_size + 1)
|
| 1186 |
|
| 1187 |
+
# Listas para almacenar las figuras de heatmap y sus nombres
|
| 1188 |
+
heatmap_figures = []
|
| 1189 |
+
heatmap_names = []
|
| 1190 |
+
|
| 1191 |
# Generar heatmaps para cada combinaci贸n de componentes
|
| 1192 |
pairs = list(itertools.combinations(range(N_COMPONENTS), 2))
|
| 1193 |
for (i, j) in pairs:
|
|
|
|
| 1224 |
# Transponer la matriz para alinear correctamente los ejes
|
| 1225 |
heatmap_data = heat_stat.T
|
| 1226 |
|
| 1227 |
+
# Definir el color mapper
|
| 1228 |
if selected_feature in model_options:
|
| 1229 |
color_mapper = LinearColorMapper(
|
| 1230 |
palette=red_green_palette,
|
|
|
|
| 1248 |
sizing_mode="fixed")
|
| 1249 |
heatmap_fig.match_aspect = True
|
| 1250 |
|
| 1251 |
+
# Asignar etiquetas a los ejes
|
| 1252 |
heatmap_fig.xaxis.axis_label = x_comp
|
| 1253 |
heatmap_fig.yaxis.axis_label = y_comp
|
| 1254 |
+
|
| 1255 |
# Dibujar la imagen del heatmap
|
| 1256 |
heatmap_fig.image(image=[heatmap_data], x=x_min, y=y_min,
|
| 1257 |
dw=x_max - x_min, dh=y_max - y_min,
|
|
|
|
| 1274 |
""")
|
| 1275 |
heatmap_fig.add_layout(color_bar, 'right')
|
| 1276 |
|
| 1277 |
+
# Agregar renderer invisible para tooltips
|
| 1278 |
source_points = ColumnDataSource(data={
|
| 1279 |
'x': df_heatmap['x'],
|
| 1280 |
'y': df_heatmap['y'],
|
|
|
|
| 1283 |
})
|
| 1284 |
invisible_renderer = heatmap_fig.circle('x', 'y', size=10, source=source_points, fill_alpha=0, line_alpha=0.5)
|
| 1285 |
|
|
|
|
| 1286 |
if select_extra_dataset_hm != "-":
|
| 1287 |
df_extra = df_all["synthetic"][df_all["synthetic"]["source"] == select_extra_dataset_hm].copy()
|
| 1288 |
df_extra["x"] = df_extra[x_comp]
|
|
|
|
| 1300 |
hover_tool_points = HoverTool(renderers=[invisible_renderer], tooltips=TOOLTIPS)
|
| 1301 |
heatmap_fig.add_tools(hover_tool_points)
|
| 1302 |
|
| 1303 |
+
# Mostrar el heatmap en la app
|
| 1304 |
st.bokeh_chart(heatmap_fig)
|
| 1305 |
+
|
| 1306 |
+
# Guardar la figura y el nombre correspondiente
|
| 1307 |
+
heatmap_figures.append(heatmap_fig)
|
| 1308 |
+
heatmap_names.append(f"heatmap_{selected_feature}_{x_comp}_vs_{y_comp}.png")
|
| 1309 |
+
|
| 1310 |
+
|
| 1311 |
+
# Inicializar el driver de Chrome en modo headless
|
| 1312 |
+
chrome_options = Options()
|
| 1313 |
+
chrome_options.add_argument("--headless")
|
| 1314 |
+
chrome_options.add_argument("--no-sandbox")
|
| 1315 |
+
chrome_options.add_argument("--disable-dev-shm-usage")
|
| 1316 |
+
driver = webdriver.Chrome(options=chrome_options, service=ChromeService(ChromeDriverManager().install()))
|
| 1317 |
+
|
| 1318 |
+
if st.button("Descargar todos los heatmaps"):
|
| 1319 |
+
zip_buffer = io.BytesIO()
|
| 1320 |
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 1321 |
+
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zip_file:
|
| 1322 |
+
# Exporta cada figura a PNG y a帽谩dela al ZIP
|
| 1323 |
+
for fig, filename in zip(heatmap_figures, heatmap_names):
|
| 1324 |
+
tmp_path = f"{tmpdirname}/{filename}"
|
| 1325 |
+
export_png(fig, filename=tmp_path, driver=driver)
|
| 1326 |
+
with open(tmp_path, "rb") as f:
|
| 1327 |
+
zip_file.writestr(filename, f.read())
|
| 1328 |
+
zip_buffer.seek(0)
|
| 1329 |
+
st.download_button(
|
| 1330 |
+
label="Descargar ZIP de heatmaps",
|
| 1331 |
+
data=zip_buffer,
|
| 1332 |
+
file_name="heatmaps.zip",
|
| 1333 |
+
mime="application/zip",
|
| 1334 |
+
key=f"download_heatmaps_{model_name}"
|
| 1335 |
+
)
|
| 1336 |
+
|
| 1337 |
+
driver.quit()
|
| 1338 |
+
|
| 1339 |
|
| 1340 |
def main():
|
| 1341 |
config_style()
|