Spaces:
Sleeping
Sleeping
Commit
·
8b0263d
1
Parent(s):
fa0575b
Visualize Images when Hovering
Browse files
app.py
CHANGED
|
@@ -558,7 +558,7 @@ def run_model(model_name):
|
|
| 558 |
return
|
| 559 |
|
| 560 |
# Nuevo selector para incluir o excluir el dataset pretrained
|
| 561 |
-
include_pretrained = st.checkbox("Incluir dataset pretrained", value=
|
| 562 |
if not include_pretrained:
|
| 563 |
# Removemos la entrada pretrained del diccionario, si existe.
|
| 564 |
embeddings.pop("pretrained", None)
|
|
@@ -890,7 +890,7 @@ def run_model(model_name):
|
|
| 890 |
legend_label=f"Real: {label}",
|
| 891 |
source=source)
|
| 892 |
|
| 893 |
-
show_real_only = st.checkbox("Show only real samples", value=
|
| 894 |
|
| 895 |
if not show_real_only:
|
| 896 |
|
|
@@ -1109,7 +1109,7 @@ def run_model(model_name):
|
|
| 1109 |
df_heatmap['x'], df_heatmap['y'], df_heatmap[selected_feature],
|
| 1110 |
statistic='mean', bins=[x_bins, y_bins]
|
| 1111 |
)
|
| 1112 |
-
except:
|
| 1113 |
cat = df_heatmap[selected_feature].astype('category')
|
| 1114 |
cat_mapping = list(cat.cat.categories)
|
| 1115 |
df_heatmap[selected_feature] = cat.cat.codes
|
|
@@ -1122,14 +1122,13 @@ def run_model(model_name):
|
|
| 1122 |
heatmap_data = heat_stat.T
|
| 1123 |
|
| 1124 |
# Crear el mapa de color
|
| 1125 |
-
color_mapper = LinearColorMapper(palette="Viridis256", low=np.nanmin(heatmap_data), high=np.nanmax(heatmap_data))
|
| 1126 |
|
| 1127 |
# Crear la figura para el heatmap con fondo blanco
|
| 1128 |
heatmap_fig = figure(title=f"Heatmap de '{selected_feature}'",
|
| 1129 |
x_range=(x_min, x_max), y_range=(y_min, y_max),
|
| 1130 |
width=600, height=600,
|
| 1131 |
-
tools="pan,wheel_zoom,reset,save", active_scroll="wheel_zoom")
|
| 1132 |
-
heatmap_fig.background_fill_color = "white"
|
| 1133 |
|
| 1134 |
# Dibujar el heatmap usando la imagen
|
| 1135 |
heatmap_fig.image(image=[heatmap_data], x=x_min, y=y_min,
|
|
@@ -1152,6 +1151,21 @@ def run_model(model_name):
|
|
| 1152 |
}}
|
| 1153 |
""")
|
| 1154 |
heatmap_fig.add_layout(color_bar, 'right')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1155 |
|
| 1156 |
st.bokeh_chart(heatmap_fig)
|
| 1157 |
|
|
|
|
| 558 |
return
|
| 559 |
|
| 560 |
# Nuevo selector para incluir o excluir el dataset pretrained
|
| 561 |
+
include_pretrained = st.checkbox("Incluir dataset pretrained", value=False, key=f"legend_{model_name}_pretrained")
|
| 562 |
if not include_pretrained:
|
| 563 |
# Removemos la entrada pretrained del diccionario, si existe.
|
| 564 |
embeddings.pop("pretrained", None)
|
|
|
|
| 890 |
legend_label=f"Real: {label}",
|
| 891 |
source=source)
|
| 892 |
|
| 893 |
+
show_real_only = st.checkbox("Show only real samples", value=True, key=f"show_real_only_{model_name}")
|
| 894 |
|
| 895 |
if not show_real_only:
|
| 896 |
|
|
|
|
| 1109 |
df_heatmap['x'], df_heatmap['y'], df_heatmap[selected_feature],
|
| 1110 |
statistic='mean', bins=[x_bins, y_bins]
|
| 1111 |
)
|
| 1112 |
+
except TypeError:
|
| 1113 |
cat = df_heatmap[selected_feature].astype('category')
|
| 1114 |
cat_mapping = list(cat.cat.categories)
|
| 1115 |
df_heatmap[selected_feature] = cat.cat.codes
|
|
|
|
| 1122 |
heatmap_data = heat_stat.T
|
| 1123 |
|
| 1124 |
# Crear el mapa de color
|
| 1125 |
+
color_mapper = LinearColorMapper(palette="Viridis256", low=np.nanmin(heatmap_data), high=np.nanmax(heatmap_data), nan_color = 'rgba(0, 0, 0, 0)')
|
| 1126 |
|
| 1127 |
# Crear la figura para el heatmap con fondo blanco
|
| 1128 |
heatmap_fig = figure(title=f"Heatmap de '{selected_feature}'",
|
| 1129 |
x_range=(x_min, x_max), y_range=(y_min, y_max),
|
| 1130 |
width=600, height=600,
|
| 1131 |
+
tools="pan,wheel_zoom,reset,save", active_scroll="wheel_zoom", tooltips=TOOLTIPS)
|
|
|
|
| 1132 |
|
| 1133 |
# Dibujar el heatmap usando la imagen
|
| 1134 |
heatmap_fig.image(image=[heatmap_data], x=x_min, y=y_min,
|
|
|
|
| 1151 |
}}
|
| 1152 |
""")
|
| 1153 |
heatmap_fig.add_layout(color_bar, 'right')
|
| 1154 |
+
|
| 1155 |
+
|
| 1156 |
+
|
| 1157 |
+
# Agregar renderer de puntos invisibles para tooltips
|
| 1158 |
+
source_points = ColumnDataSource(data={
|
| 1159 |
+
'x': df_heatmap['x'],
|
| 1160 |
+
'y': df_heatmap['y'],
|
| 1161 |
+
'img': df_heatmap['img'],
|
| 1162 |
+
'label': df_heatmap['name'] # Asegúrate de que esta columna exista; si no, usa otra
|
| 1163 |
+
})
|
| 1164 |
+
# Dibujar círculos con transparencia total (no se verán)
|
| 1165 |
+
invisible_renderer = heatmap_fig.circle('x', 'y', size=10, source=source_points, fill_alpha=0, line_alpha=0.5)
|
| 1166 |
+
|
| 1167 |
+
hover_tool_points = HoverTool(renderers=[invisible_renderer], tooltips=TOOLTIPS)
|
| 1168 |
+
heatmap_fig.add_tools(hover_tool_points)
|
| 1169 |
|
| 1170 |
st.bokeh_chart(heatmap_fig)
|
| 1171 |
|