Spaces:
Running
on
Zero
Running
on
Zero
update msg
Browse files
app.py
CHANGED
@@ -2465,7 +2465,7 @@ with demo:
|
|
2465 |
text_block = gr.Textbox("", label="Logging", elem_id=f"logging_{i_row}", type="text", placeholder="Logging information", autofocus=False, autoscroll=False, lines=2, show_label=False)
|
2466 |
delete_button = gr.Button("❌ Delete", elem_id=f"delete_button_{i_row}", variant='secondary')
|
2467 |
with gr.Column(scale=10, min_width=200):
|
2468 |
-
heatmap_gallery = gr.Gallery(format='png', value=[], label=f"Cluster Heatmap [row#{i_row}]", show_label=True, elem_id="heatmap", columns=[6], rows=[1], object_fit="contain", height="
|
2469 |
def delete_a_row(output_row_occupy, i_row=1):
|
2470 |
# output_row_occupy[i_row-1] = False
|
2471 |
return output_row_occupy, gr.update(visible=False)
|
@@ -2513,6 +2513,7 @@ with demo:
|
|
2513 |
|
2514 |
def find_closest_fps_point_for_tsne_tree_plot(tsne_prompt, tsne2d_embed):
|
2515 |
x, y = relative_xy_last_positive(tsne_prompt)
|
|
|
2516 |
x_vmax = tsne2d_embed[:, 0].max() * 1.1
|
2517 |
x_vmin = tsne2d_embed[:, 0].min() * 1.1
|
2518 |
y_vmax = tsne2d_embed[:, 1].max() * 1.1
|
@@ -2522,10 +2523,11 @@ with demo:
|
|
2522 |
y = y * (y_vmax - y_vmin) + y_vmin
|
2523 |
dist = np.linalg.norm(tsne2d_embed - np.array([x, y]), axis=1)
|
2524 |
closest_idx = np.argmin(dist)
|
2525 |
-
return closest_idx
|
2526 |
|
2527 |
def find_closest_fps_point_for_image_prompt(image_prompt, i_image, eigvecs, fps_eigvecs):
|
2528 |
x, y = relative_xy_last_positive(image_prompt)
|
|
|
2529 |
_eigvec = eigvecs[i_image]
|
2530 |
h, w = _eigvec.shape[:2]
|
2531 |
x = int(x * w)
|
@@ -2533,7 +2535,7 @@ with demo:
|
|
2533 |
eigvec = _eigvec[y, x]
|
2534 |
sim = fps_eigvecs @ eigvec
|
2535 |
closest_idx = np.argmax(sim)
|
2536 |
-
return closest_idx
|
2537 |
|
2538 |
def find_closest_fps_point(prompt_radio, tsne_prompt, image_prompt, i_image, tsne2d_embed, eigvecs, fps_eigvecs):
|
2539 |
try:
|
@@ -2547,15 +2549,15 @@ with demo:
|
|
2547 |
def run_inspection(tsne_prompt, image_prompt, prompt_radio, current_output_row, tsne2d_embed, edges, fps_eigvecs, fps_tsne_rgb, fps_indices, granularity, eigvecs, i_image, tsne3d_rgb, input_gallery, output_row_occupy, max_rows=MAX_ROWS):
|
2548 |
if len(tsne2d_embed) == 0:
|
2549 |
raise gr.Error("Please run FPS+Cluster first.")
|
2550 |
-
closest_idx = find_closest_fps_point(prompt_radio, tsne_prompt, image_prompt, i_image, tsne2d_embed, eigvecs, fps_eigvecs)
|
2551 |
closest_rgb = fps_tsne_rgb[closest_idx]
|
2552 |
closest_rgb = (closest_rgb * 255).astype(np.uint8)
|
2553 |
|
2554 |
from fps_cluster import find_connected_component
|
2555 |
connected_idxs = find_connected_component(edges[granularity:], closest_idx)
|
2556 |
|
2557 |
-
logging_text = f"Clicked: idx={closest_idx},
|
2558 |
-
logging_text += f"
|
2559 |
|
2560 |
output_tsne_plot = plot_tsne_tree(tsne2d_embed, edges, fps_tsne_rgb, granularity, closest_idx, highlight_connections=True)
|
2561 |
|
@@ -2610,7 +2612,7 @@ with demo:
|
|
2610 |
output_row_occupy[i_slot] = True
|
2611 |
# tree_label = f"spectral-tSNE tree [row#{max_rows-output_slot}] k={granularity} idx={closest_idx} n={len(connected_idxs)}"
|
2612 |
tree_label = f"spectral-tSNE tree [row#{current_output_row+1}]"
|
2613 |
-
heatmap_label = f"Cluster Heatmap [row#{current_output_row+1}] k={granularity}
|
2614 |
# update the output slots
|
2615 |
output_rows = [gr.update() for _ in range(max_rows)]
|
2616 |
output_tsne_plots = [gr.update() for _ in range(max_rows)]
|
|
|
2465 |
text_block = gr.Textbox("", label="Logging", elem_id=f"logging_{i_row}", type="text", placeholder="Logging information", autofocus=False, autoscroll=False, lines=2, show_label=False)
|
2466 |
delete_button = gr.Button("❌ Delete", elem_id=f"delete_button_{i_row}", variant='secondary')
|
2467 |
with gr.Column(scale=10, min_width=200):
|
2468 |
+
heatmap_gallery = gr.Gallery(format='png', value=[], label=f"Cluster Heatmap [row#{i_row}]", show_label=True, elem_id="heatmap", columns=[6], rows=[1], object_fit="contain", height="550px", show_share_button=True, interactive=False)
|
2469 |
def delete_a_row(output_row_occupy, i_row=1):
|
2470 |
# output_row_occupy[i_row-1] = False
|
2471 |
return output_row_occupy, gr.update(visible=False)
|
|
|
2513 |
|
2514 |
def find_closest_fps_point_for_tsne_tree_plot(tsne_prompt, tsne2d_embed):
|
2515 |
x, y = relative_xy_last_positive(tsne_prompt)
|
2516 |
+
_x_ratio, _y_ratio = x, y
|
2517 |
x_vmax = tsne2d_embed[:, 0].max() * 1.1
|
2518 |
x_vmin = tsne2d_embed[:, 0].min() * 1.1
|
2519 |
y_vmax = tsne2d_embed[:, 1].max() * 1.1
|
|
|
2523 |
y = y * (y_vmax - y_vmin) + y_vmin
|
2524 |
dist = np.linalg.norm(tsne2d_embed - np.array([x, y]), axis=1)
|
2525 |
closest_idx = np.argmin(dist)
|
2526 |
+
return closest_idx, (_x_ratio, _y_ratio)
|
2527 |
|
2528 |
def find_closest_fps_point_for_image_prompt(image_prompt, i_image, eigvecs, fps_eigvecs):
|
2529 |
x, y = relative_xy_last_positive(image_prompt)
|
2530 |
+
_x_ratio, _y_ratio = x, y
|
2531 |
_eigvec = eigvecs[i_image]
|
2532 |
h, w = _eigvec.shape[:2]
|
2533 |
x = int(x * w)
|
|
|
2535 |
eigvec = _eigvec[y, x]
|
2536 |
sim = fps_eigvecs @ eigvec
|
2537 |
closest_idx = np.argmax(sim)
|
2538 |
+
return closest_idx, (_x_ratio, _y_ratio)
|
2539 |
|
2540 |
def find_closest_fps_point(prompt_radio, tsne_prompt, image_prompt, i_image, tsne2d_embed, eigvecs, fps_eigvecs):
|
2541 |
try:
|
|
|
2549 |
def run_inspection(tsne_prompt, image_prompt, prompt_radio, current_output_row, tsne2d_embed, edges, fps_eigvecs, fps_tsne_rgb, fps_indices, granularity, eigvecs, i_image, tsne3d_rgb, input_gallery, output_row_occupy, max_rows=MAX_ROWS):
|
2550 |
if len(tsne2d_embed) == 0:
|
2551 |
raise gr.Error("Please run FPS+Cluster first.")
|
2552 |
+
closest_idx, (_x, _y) = find_closest_fps_point(prompt_radio, tsne_prompt, image_prompt, i_image, tsne2d_embed, eigvecs, fps_eigvecs)
|
2553 |
closest_rgb = fps_tsne_rgb[closest_idx]
|
2554 |
closest_rgb = (closest_rgb * 255).astype(np.uint8)
|
2555 |
|
2556 |
from fps_cluster import find_connected_component
|
2557 |
connected_idxs = find_connected_component(edges[granularity:], closest_idx)
|
2558 |
|
2559 |
+
logging_text = f"Clicked: idx={closest_idx}, xy=[{_x:.2f}, {_y:.2f}], RGB={closest_rgb}"
|
2560 |
+
logging_text += f"\nGranularity: k={granularity}, Connected: n={len(connected_idxs)}"
|
2561 |
|
2562 |
output_tsne_plot = plot_tsne_tree(tsne2d_embed, edges, fps_tsne_rgb, granularity, closest_idx, highlight_connections=True)
|
2563 |
|
|
|
2612 |
output_row_occupy[i_slot] = True
|
2613 |
# tree_label = f"spectral-tSNE tree [row#{max_rows-output_slot}] k={granularity} idx={closest_idx} n={len(connected_idxs)}"
|
2614 |
tree_label = f"spectral-tSNE tree [row#{current_output_row+1}]"
|
2615 |
+
heatmap_label = f"Cluster Heatmap [row#{current_output_row+1}] k={granularity} n={len(connected_idxs)} xy=[{_x:.2f}, {_y:.2f}] idx={closest_idx}"
|
2616 |
# update the output slots
|
2617 |
output_rows = [gr.update() for _ in range(max_rows)]
|
2618 |
output_tsne_plots = [gr.update() for _ in range(max_rows)]
|