Spaces:
Running
on
Zero
Running
on
Zero
better UI
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import time
|
|
8 |
|
9 |
import gradio as gr
|
10 |
|
11 |
-
from
|
12 |
from ncut_pytorch import NCUT, rgb_from_tsne_3d, rgb_from_umap_3d
|
13 |
|
14 |
|
@@ -138,7 +138,7 @@ def ncut_run(
|
|
138 |
)
|
139 |
logging_str += _logging_str
|
140 |
rgb = dont_use_too_much_green(rgb)
|
141 |
-
return to_pil_images(rgb),
|
142 |
|
143 |
@spaces.GPU(duration=15)
|
144 |
def quick_run(images, **kwargs):
|
@@ -173,7 +173,7 @@ def run_fn(
|
|
173 |
min_dist=0.1,
|
174 |
):
|
175 |
if images is None:
|
176 |
-
return [],
|
177 |
|
178 |
kwargs = {
|
179 |
"model_name": model_name,
|
@@ -217,8 +217,14 @@ with gr.Blocks() as demo:
|
|
217 |
|
218 |
gr.Markdown('### Load Examples 👇')
|
219 |
load_images_button = gr.Button("Load", elem_id="load-images-button")
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
with gr.Column(scale=5, min_width=200):
|
223 |
gr.Markdown('### Output Images')
|
224 |
output_gallery = gr.Gallery(value=[], label="NCUT Embedding", show_label=False, elem_id="ncut", columns=[3], rows=[1], object_fit="contain", height="auto")
|
@@ -242,11 +248,18 @@ with gr.Blocks() as demo:
|
|
242 |
logging_text = gr.Textbox("Logging information", label="Logging", elem_id="logging", type="text", placeholder="Logging information")
|
243 |
|
244 |
def load_default_images():
|
245 |
-
return default_images, default_outputs,
|
246 |
|
247 |
def empty_input_and_output():
|
248 |
return [], [], example_items
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
load_images_button.click(load_default_images, outputs=[input_gallery, output_gallery, example_gallery])
|
251 |
clear_images_button.click(empty_input_and_output, outputs=[input_gallery, output_gallery, example_gallery])
|
252 |
submit_button.click(
|
@@ -257,7 +270,7 @@ with gr.Blocks() as demo:
|
|
257 |
embedding_method_dropdown, num_sample_tsne_slider, knn_tsne_slider,
|
258 |
perplexity_slider, n_neighbors_slider, min_dist_slider
|
259 |
],
|
260 |
-
outputs=[output_gallery,
|
261 |
)
|
262 |
|
263 |
|
|
|
8 |
|
9 |
import gradio as gr
|
10 |
|
11 |
+
from draft_gradio_backbone import extract_features
|
12 |
from ncut_pytorch import NCUT, rgb_from_tsne_3d, rgb_from_umap_3d
|
13 |
|
14 |
|
|
|
138 |
)
|
139 |
logging_str += _logging_str
|
140 |
rgb = dont_use_too_much_green(rgb)
|
141 |
+
return to_pil_images(rgb), logging_str
|
142 |
|
143 |
@spaces.GPU(duration=15)
|
144 |
def quick_run(images, **kwargs):
|
|
|
173 |
min_dist=0.1,
|
174 |
):
|
175 |
if images is None:
|
176 |
+
return [], "No images selected."
|
177 |
|
178 |
kwargs = {
|
179 |
"model_name": model_name,
|
|
|
217 |
|
218 |
gr.Markdown('### Load Examples 👇')
|
219 |
load_images_button = gr.Button("Load", elem_id="load-images-button")
|
220 |
+
hide_button = gr.Button("Hide", elem_id="hide-button")
|
221 |
+
example_gallery = gr.Gallery(value=example_items, label="Example Set A", show_label=False, columns=[3], rows=[2], object_fit="scale-down", height="200px", show_share_button=False, elem_id="example-gallery")
|
222 |
+
|
223 |
+
hide_button.click(
|
224 |
+
fn=lambda: gr.update(visible=False),
|
225 |
+
outputs=example_gallery
|
226 |
+
)
|
227 |
+
|
228 |
with gr.Column(scale=5, min_width=200):
|
229 |
gr.Markdown('### Output Images')
|
230 |
output_gallery = gr.Gallery(value=[], label="NCUT Embedding", show_label=False, elem_id="ncut", columns=[3], rows=[1], object_fit="contain", height="auto")
|
|
|
248 |
logging_text = gr.Textbox("Logging information", label="Logging", elem_id="logging", type="text", placeholder="Logging information")
|
249 |
|
250 |
def load_default_images():
|
251 |
+
return default_images, default_outputs, example_items
|
252 |
|
253 |
def empty_input_and_output():
|
254 |
return [], [], example_items
|
255 |
|
256 |
+
def hide_example_gallery(images):
|
257 |
+
if images is None:
|
258 |
+
return
|
259 |
+
|
260 |
+
# hide the example gallery, use css to hide
|
261 |
+
|
262 |
+
|
263 |
load_images_button.click(load_default_images, outputs=[input_gallery, output_gallery, example_gallery])
|
264 |
clear_images_button.click(empty_input_and_output, outputs=[input_gallery, output_gallery, example_gallery])
|
265 |
submit_button.click(
|
|
|
270 |
embedding_method_dropdown, num_sample_tsne_slider, knn_tsne_slider,
|
271 |
perplexity_slider, n_neighbors_slider, min_dist_slider
|
272 |
],
|
273 |
+
outputs=[output_gallery, logging_text]
|
274 |
)
|
275 |
|
276 |
|