Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse filesdelete other code
app.py
CHANGED
@@ -58,68 +58,12 @@ def load_image_ui(load_edit, input_folder="example_tmp"):
|
|
58 |
segmentation = create_segmentation(mask_np_list)
|
59 |
print("!!", len(mask_np_list))
|
60 |
max_val = len(mask_np_list)-1
|
61 |
-
sliderup = gr.Slider(value = 0, minimum=0, maximum=max_val, step=1,
|
62 |
return image, segmentation, mask_np_list, mask_label_list, image, sliderup
|
63 |
except:
|
64 |
print("Image folder invalid: The folder should contain image.png")
|
65 |
-
return None, None, None, None, None
|
66 |
-
|
67 |
-
# def run_edit_text(
|
68 |
-
# num_tokens,
|
69 |
-
# num_sampling_steps,
|
70 |
-
# strength,
|
71 |
-
# edge_thickness,
|
72 |
-
# tgt_prompt,
|
73 |
-
# tgt_idx,
|
74 |
-
# guidance_scale,
|
75 |
-
# input_folder="example_tmp"
|
76 |
-
# ):
|
77 |
-
# subprocess.run(["python",
|
78 |
-
# "main.py" ,
|
79 |
-
# "--text=True",
|
80 |
-
# "--name={}".format(input_folder),
|
81 |
-
# "--dpm={}".format("sd"),
|
82 |
-
# "--resolution={}".format(512),
|
83 |
-
# "--load_trained",
|
84 |
-
# "--num_tokens={}".format(num_tokens),
|
85 |
-
# "--seed={}".format(2024),
|
86 |
-
# "--guidance_scale={}".format(guidance_scale),
|
87 |
-
# "--num_sampling_step={}".format(num_sampling_steps),
|
88 |
-
# "--strength={}".format(strength),
|
89 |
-
# "--edge_thickness={}".format(edge_thickness),
|
90 |
-
# "--num_imgs={}".format(2),
|
91 |
-
# "--tgt_prompt={}".format(tgt_prompt) ,
|
92 |
-
# "--tgt_index={}".format(tgt_idx)
|
93 |
-
# ])
|
94 |
-
|
95 |
-
# return Image.open(os.path.join(input_folder, "text", "out_text_0.png"))
|
96 |
-
|
97 |
-
|
98 |
-
# def run_optimization(
|
99 |
-
# num_tokens,
|
100 |
-
# embedding_learning_rate,
|
101 |
-
# max_emb_train_steps,
|
102 |
-
# diffusion_model_learning_rate,
|
103 |
-
# max_diffusion_train_steps,
|
104 |
-
# train_batch_size,
|
105 |
-
# gradient_accumulation_steps,
|
106 |
-
# input_folder = "example_tmp"
|
107 |
-
# ):
|
108 |
-
# subprocess.run(["python",
|
109 |
-
# "main.py" ,
|
110 |
-
# "--name={}".format(input_folder),
|
111 |
-
# "--dpm={}".format("sd"),
|
112 |
-
# "--resolution={}".format(512),
|
113 |
-
# "--num_tokens={}".format(num_tokens),
|
114 |
-
# "--embedding_learning_rate={}".format(embedding_learning_rate),
|
115 |
-
# "--diffusion_model_learning_rate={}".format(diffusion_model_learning_rate),
|
116 |
-
# "--max_emb_train_steps={}".format(max_emb_train_steps),
|
117 |
-
# "--max_diffusion_train_steps={}".format(max_diffusion_train_steps),
|
118 |
-
# "--train_batch_size={}".format(train_batch_size),
|
119 |
-
# "--gradient_accumulation_steps={}".format(gradient_accumulation_steps)
|
120 |
-
|
121 |
-
# ])
|
122 |
-
# return
|
123 |
|
124 |
|
125 |
def transparent_paste_with_mask(backimg, foreimg, mask_np,transparency = 128):
|
@@ -255,63 +199,26 @@ with gr.Blocks() as demo:
|
|
255 |
|
256 |
text_button = gr.Button("Waiting 1.1 to complete",visible = False)
|
257 |
|
258 |
-
|
259 |
-
|
260 |
-
# show_segment = gr.Checkbox(label = "Waiting 1.1 to complete",visible = False)
|
261 |
flag = gr.State(False)
|
262 |
-
|
263 |
-
# [image_loaded, segmentation, flag],
|
264 |
-
# [canvas, flag])
|
265 |
-
#def show_more_buttons():
|
266 |
-
# return gr.Button("1.2 Load original masks",visible = True), gr.Button("1.2 Load edited masks") , gr.Checkbox(label = "Show Segmentation")
|
267 |
-
#block_flag.change(show_more_buttons, [], [text_button,load_edit_button,show_segment ])
|
268 |
-
|
269 |
-
|
270 |
# mask_np_list_updated.value = copy.deepcopy(mask_np_list.value) #!!
|
271 |
mask_np_list_updated = mask_np_list
|
272 |
with gr.Column():
|
273 |
gr.Markdown("""<p style="text-align: center; font-size: 20px">Edit Mask (Optional)</p>""")
|
274 |
-
slider = gr.Slider(0, 20, step=1, interactive=False)
|
275 |
label = gr.Textbox()
|
276 |
slider.release(slider_release,
|
277 |
inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
|
278 |
outputs= [canvas, label]
|
279 |
)
|
280 |
-
# add_button = gr.Button("Add")
|
281 |
-
# add_button.click( edit_mask_add,
|
282 |
-
# [canvas, image_loaded, slider, mask_np_list_updated] ,
|
283 |
-
# [mask_np_list_updated, canvas]
|
284 |
-
# )
|
285 |
-
|
286 |
-
# save_button2 = gr.Button("Set and Save as edited masks")
|
287 |
-
# save_button2.click( save_as_edit_mask,
|
288 |
-
# [mask_np_list_updated, mask_label_list] ,
|
289 |
-
# [] )
|
290 |
-
|
291 |
-
# save_button = gr.Button("Set and Save as original masks")
|
292 |
-
# save_button.click( save_as_orig_mask,
|
293 |
-
# [mask_np_list_updated, mask_label_list] ,
|
294 |
-
# [] )
|
295 |
-
|
296 |
-
# back_button = gr.Button("Back to current seg")
|
297 |
-
# back_button.click( load_mask_ui,
|
298 |
-
# [] ,
|
299 |
-
# [ mask_np_list_updated,mask_label_list] )
|
300 |
-
|
301 |
-
# add_mask_button = gr.Button("Add new empty mask")
|
302 |
-
# add_mask_button.click(add_mask,
|
303 |
-
# [mask_np_list_updated, mask_label_list] ,
|
304 |
-
# [mask_np_list_updated, mask_label_list] )
|
305 |
-
|
306 |
|
307 |
segment_button.click(run_segmentation,
|
308 |
[canvas] ,
|
309 |
[text_button] )
|
310 |
text_button.click(load_image_ui, [false] ,
|
311 |
[image_loaded, segmentation, mask_np_list, mask_label_list, canvas, slider] )
|
312 |
-
|
313 |
-
# load_edit_button.click(load_image_ui, [ true] ,
|
314 |
-
# [image_loaded, segmentation, mask_np_list, mask_label_list, canvas, slider] )
|
315 |
|
316 |
canvas.upload(image_change, inputs=[], outputs=[text_button])
|
317 |
|
@@ -382,12 +289,7 @@ with gr.Blocks() as demo:
|
|
382 |
#add_button.update()
|
383 |
def change_text():
|
384 |
return gr.Textbox("Optimization Finished!", interactive = False)
|
385 |
-
|
386 |
-
inputs=[txt_box], outputs=[add_button])
|
387 |
-
def change_text2():
|
388 |
-
return gr.Textbox("Start optimization, check logs for progress...", interactive = False)
|
389 |
-
add_button.click(change_text2, [], txt_box)'''
|
390 |
-
#opt_flag.change(change_text, txt_box, txt_box)
|
391 |
|
392 |
with gr.Tab(label="3 Editing"):
|
393 |
with gr.Tab(label="3.1 Text-based editing"):
|
@@ -446,11 +348,7 @@ with gr.Blocks() as demo:
|
|
446 |
outputs = [canvas_text_edit],queue=True,
|
447 |
)
|
448 |
|
449 |
-
|
450 |
-
load_button.click(load_pil_img,
|
451 |
-
inputs = [],
|
452 |
-
outputs = [canvas_text_edit]
|
453 |
-
)
|
454 |
|
455 |
|
456 |
|
|
|
58 |
segmentation = create_segmentation(mask_np_list)
|
59 |
print("!!", len(mask_np_list))
|
60 |
max_val = len(mask_np_list)-1
|
61 |
+
sliderup = gr.Slider(value = 0, minimum=0, maximum=max_val, step=1, interactive=True)
|
62 |
return image, segmentation, mask_np_list, mask_label_list, image, sliderup
|
63 |
except:
|
64 |
print("Image folder invalid: The folder should contain image.png")
|
65 |
+
return None, None, None, None, None, None
|
66 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
|
69 |
def transparent_paste_with_mask(backimg, foreimg, mask_np,transparency = 128):
|
|
|
199 |
|
200 |
text_button = gr.Button("Waiting 1.1 to complete",visible = False)
|
201 |
|
202 |
+
|
|
|
|
|
203 |
flag = gr.State(False)
|
204 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
# mask_np_list_updated.value = copy.deepcopy(mask_np_list.value) #!!
|
206 |
mask_np_list_updated = mask_np_list
|
207 |
with gr.Column():
|
208 |
gr.Markdown("""<p style="text-align: center; font-size: 20px">Edit Mask (Optional)</p>""")
|
209 |
+
slider = gr.Slider(0, 20, step=1, label = 'mask id', interactive=False)
|
210 |
label = gr.Textbox()
|
211 |
slider.release(slider_release,
|
212 |
inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
|
213 |
outputs= [canvas, label]
|
214 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
segment_button.click(run_segmentation,
|
217 |
[canvas] ,
|
218 |
[text_button] )
|
219 |
text_button.click(load_image_ui, [false] ,
|
220 |
[image_loaded, segmentation, mask_np_list, mask_label_list, canvas, slider] )
|
221 |
+
|
|
|
|
|
222 |
|
223 |
canvas.upload(image_change, inputs=[], outputs=[text_button])
|
224 |
|
|
|
289 |
#add_button.update()
|
290 |
def change_text():
|
291 |
return gr.Textbox("Optimization Finished!", interactive = False)
|
292 |
+
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
with gr.Tab(label="3 Editing"):
|
295 |
with gr.Tab(label="3.1 Text-based editing"):
|
|
|
348 |
outputs = [canvas_text_edit],queue=True,
|
349 |
)
|
350 |
|
351 |
+
|
|
|
|
|
|
|
|
|
352 |
|
353 |
|
354 |
|