Spaces:
Running
on
Zero
Running
on
Zero
update ui
Browse files
app.py
CHANGED
@@ -77,6 +77,14 @@ def to_pil_images(images):
|
|
77 |
for image in images
|
78 |
]
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
@spaces.GPU(duration=30)
|
81 |
def main_fn(
|
82 |
images,
|
@@ -94,6 +102,9 @@ def main_fn(
|
|
94 |
n_neighbors=500,
|
95 |
min_dist=0.1,
|
96 |
):
|
|
|
|
|
|
|
97 |
if perplexity >= num_sample_tsne or n_neighbors >= num_sample_tsne:
|
98 |
# raise gr.Error("Perplexity must be less than the number of samples for t-SNE.")
|
99 |
gr.Warning("Perplexity/n_neighbors must be less than the number of samples.\n" f"Setting to {num_sample_tsne-1}.")
|
@@ -125,13 +136,8 @@ def main_fn(
|
|
125 |
min_dist=min_dist,
|
126 |
)
|
127 |
rgb = dont_use_too_much_green(rgb)
|
128 |
-
return to_pil_images(rgb)
|
129 |
-
|
130 |
-
default_images = ['./images/image_0.jpg', './images/image_1.jpg', './images/image_2.jpg', './images/image_3.jpg', './images/image_5.jpg']
|
131 |
-
default_outputs = ['./images/ncut_0.jpg', './images/ncut_1.jpg', './images/ncut_2.jpg', './images/ncut_3.jpg', './images/ncut_5.jpg']
|
132 |
|
133 |
-
downscaled_images = ['./images/image_0_small.jpg', './images/image_1_small.jpg', './images/image_2_small.jpg', './images/image_3_small.jpg', './images/image_5_small.jpg']
|
134 |
-
downscaled_outputs = ['./images/ncut_0_small.jpg', './images/ncut_1_small.jpg', './images/ncut_2_small.jpg', './images/ncut_3_small.jpg', './images/ncut_5_small.jpg']
|
135 |
|
136 |
with gr.Blocks() as demo:
|
137 |
|
@@ -144,7 +150,7 @@ with gr.Blocks() as demo:
|
|
144 |
|
145 |
gr.Markdown('### Load Examples 👇')
|
146 |
load_images_button = gr.Button("Load", elem_id="load-images-button")
|
147 |
-
gr.Gallery(value=
|
148 |
|
149 |
with gr.Column(scale=5, min_width=200):
|
150 |
gr.Markdown('### Output Images')
|
@@ -166,12 +172,12 @@ with gr.Blocks() as demo:
|
|
166 |
min_dist_slider = gr.Slider(0.1, 1, step=0.1, label="min_dist (UMAP)", value=0.1, elem_id="min_dist")
|
167 |
|
168 |
def load_default_images():
|
169 |
-
return default_images, default_outputs
|
170 |
|
171 |
def empty_input_and_output():
|
172 |
return [], []
|
173 |
|
174 |
-
load_images_button.click(load_default_images, outputs=[input_gallery, output_gallery])
|
175 |
clear_images_button.click(empty_input_and_output, outputs=[input_gallery, output_gallery])
|
176 |
submit_button.click(
|
177 |
main_fn,
|
@@ -181,7 +187,7 @@ with gr.Blocks() as demo:
|
|
181 |
embedding_method_dropdown, num_sample_tsne_slider, knn_tsne_slider,
|
182 |
perplexity_slider, n_neighbors_slider, min_dist_slider
|
183 |
],
|
184 |
-
outputs=output_gallery
|
185 |
)
|
186 |
|
187 |
|
|
|
77 |
for image in images
|
78 |
]
|
79 |
|
80 |
+
default_images = ['./images/image_0.jpg', './images/image_1.jpg', './images/image_2.jpg', './images/image_3.jpg', './images/image_5.jpg']
|
81 |
+
default_outputs = ['./images/ncut_0.jpg', './images/ncut_1.jpg', './images/ncut_2.jpg', './images/ncut_3.jpg', './images/ncut_5.jpg']
|
82 |
+
|
83 |
+
downscaled_images = ['./images/image_0_small.jpg', './images/image_1_small.jpg', './images/image_2_small.jpg', './images/image_3_small.jpg', './images/image_5_small.jpg']
|
84 |
+
downscaled_outputs = ['./images/ncut_0_small.jpg', './images/ncut_1_small.jpg', './images/ncut_2_small.jpg', './images/ncut_3_small.jpg', './images/ncut_5_small.jpg']
|
85 |
+
|
86 |
+
example_items = downscaled_images[:3] + downscaled_outputs[:3]
|
87 |
+
|
88 |
@spaces.GPU(duration=30)
|
89 |
def main_fn(
|
90 |
images,
|
|
|
102 |
n_neighbors=500,
|
103 |
min_dist=0.1,
|
104 |
):
|
105 |
+
if len(images) == 0:
|
106 |
+
return [], example_items
|
107 |
+
|
108 |
if perplexity >= num_sample_tsne or n_neighbors >= num_sample_tsne:
|
109 |
# raise gr.Error("Perplexity must be less than the number of samples for t-SNE.")
|
110 |
gr.Warning("Perplexity/n_neighbors must be less than the number of samples.\n" f"Setting to {num_sample_tsne-1}.")
|
|
|
136 |
min_dist=min_dist,
|
137 |
)
|
138 |
rgb = dont_use_too_much_green(rgb)
|
139 |
+
return to_pil_images(rgb), []
|
|
|
|
|
|
|
140 |
|
|
|
|
|
141 |
|
142 |
with gr.Blocks() as demo:
|
143 |
|
|
|
150 |
|
151 |
gr.Markdown('### Load Examples 👇')
|
152 |
load_images_button = gr.Button("Load", elem_id="load-images-button")
|
153 |
+
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)
|
154 |
|
155 |
with gr.Column(scale=5, min_width=200):
|
156 |
gr.Markdown('### Output Images')
|
|
|
172 |
min_dist_slider = gr.Slider(0.1, 1, step=0.1, label="min_dist (UMAP)", value=0.1, elem_id="min_dist")
|
173 |
|
174 |
def load_default_images():
|
175 |
+
return default_images, default_outputs, []
|
176 |
|
177 |
def empty_input_and_output():
|
178 |
return [], []
|
179 |
|
180 |
+
load_images_button.click(load_default_images, outputs=[input_gallery, output_gallery, example_gallery])
|
181 |
clear_images_button.click(empty_input_and_output, outputs=[input_gallery, output_gallery])
|
182 |
submit_button.click(
|
183 |
main_fn,
|
|
|
187 |
embedding_method_dropdown, num_sample_tsne_slider, knn_tsne_slider,
|
188 |
perplexity_slider, n_neighbors_slider, min_dist_slider
|
189 |
],
|
190 |
+
outputs=[output_gallery, example_gallery]
|
191 |
)
|
192 |
|
193 |
|