Spaces:
Running
Running
Linoy Tsaban
commited on
Commit
•
cbeefd9
1
Parent(s):
36d95bc
Update app.py
Browse files- fixed bug in re-computing of reconstruction
- auto captioning
- moved clear and show reconstruction buttons to advanced options
- sega edit concepts relocated
app.py
CHANGED
@@ -130,29 +130,40 @@ def edit(input_image,
|
|
130 |
guidnace_scale_1,guidnace_scale_2,guidnace_scale_3,
|
131 |
warmup_1, warmup_2, warmup_3,
|
132 |
neg_guidance_1, neg_guidance_2, neg_guidance_3,
|
133 |
-
threshold_1, threshold_2, threshold_3
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
def randomize_seed_fn(seed, randomize_seed):
|
158 |
if randomize_seed:
|
@@ -271,35 +282,29 @@ with gr.Blocks(css="style.css") as demo:
|
|
271 |
if sega_concepts_counter == 1:
|
272 |
return row2.update(visible=True), row2_advanced.update(visible=True), row3.update(visible=False), row3_advanced.update(visible=False), add_concept_button.update(visible=True), 2
|
273 |
else:
|
274 |
-
return row2.update(visible=True), row2_advanced.update(visible=True), row3.update(visible=True), row3_advanced.update(visible=
|
275 |
|
276 |
-
def update_display_concept_1(add_1, edit_concept_1):
|
277 |
-
if add_1 == 'Add':
|
278 |
-
return box1.update(visible=True), edit_concept_1, concept_1.update(visible=True), edit_concept_1, guidnace_scale_1.update(visible=True), "Clear"
|
279 |
else: # remove
|
280 |
-
return box1.update(visible=False),"", concept_1.update(visible=False), "", guidnace_scale_1.update(visible=False), "Add"
|
281 |
|
282 |
-
def update_display_concept_2(add_2, edit_concept_2):
|
283 |
-
if add_2 == 'Add':
|
284 |
-
return box2.update(visible=True), edit_concept_2, concept_2.update(visible=True),edit_concept_2, guidnace_scale_2.update(visible=True), "Clear"
|
285 |
else: # remove
|
286 |
-
return box2.update(visible=False),"", concept_2.update(visible=False), "", guidnace_scale_2.update(visible=False), "Add"
|
287 |
|
288 |
-
def update_display_concept_3(add_3, edit_concept_3):
|
289 |
-
if add_3 == 'Add':
|
290 |
-
return box3.update(visible=True), edit_concept_3, concept_3.update(visible=True), edit_concept_3, guidnace_scale_3.update(visible=True), "Clear"
|
291 |
else: # remove
|
292 |
-
return box3.update(visible=False), "", concept_3.update(visible=False), "", guidnace_scale_3.update(visible=False), "Add"
|
293 |
|
294 |
def display_editing_options(run_button, clear_button, sega_tab):
|
295 |
return run_button.update(visible=True), clear_button.update(visible=True), sega_tab.update(visible=True)
|
296 |
|
297 |
-
def update_edit_concept(concept, edit_concept, add):
|
298 |
-
if add == "Clear":
|
299 |
-
return edit_concept
|
300 |
-
else:
|
301 |
-
return concept
|
302 |
-
|
303 |
# def update_gallery_display(prev_output_image, sega_edited_image):
|
304 |
# if prev_output_image is None:
|
305 |
# return sega_edited_image, gallery.update(visible=True), sega_edited_image
|
@@ -335,19 +340,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
335 |
sega_concepts_counter = gr.State(1)
|
336 |
|
337 |
|
338 |
-
#Undo / gallery
|
339 |
-
# prev_wts = gr.State()
|
340 |
-
# prev_zs = gr.State()
|
341 |
-
# prev_src_prompt = gr.State()
|
342 |
-
# prev_tar_prompt = gr.State()
|
343 |
-
# prev_tar_guidance_scale = gr.State()
|
344 |
-
# prev_src_guidance_scale = gr.State()
|
345 |
-
# prev_num_steps = gr.State()
|
346 |
-
# prev_skip = gr.State()
|
347 |
-
# prev_output_image = gr.Image(visible=False)
|
348 |
-
# prev_input_image = gr.State()
|
349 |
-
|
350 |
-
|
351 |
|
352 |
with gr.Row():
|
353 |
input_image = gr.Image(label="Input Image", interactive=True)
|
@@ -375,103 +367,106 @@ with gr.Blocks(css="style.css") as demo:
|
|
375 |
step=0.5, interactive=True,visible=False)
|
376 |
|
377 |
|
378 |
-
|
379 |
-
# with gr.Row():
|
380 |
-
# gallery = gr.Gallery(label = "History", visible = True).style(
|
381 |
-
# columns=1,rows=1,
|
382 |
-
# object_fit='contain')
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
with gr.Row():
|
387 |
inversion_progress = gr.Textbox(visible=False, label="Inversion progress")
|
388 |
|
389 |
-
with gr.Tabs() as tabs:
|
390 |
-
with gr.TabItem('1. Describe the desired output', id=0):
|
391 |
-
|
392 |
tar_prompt = gr.Textbox(
|
393 |
-
label="
|
394 |
show_label=False,
|
395 |
-
max_lines=1,
|
396 |
-
placeholder="Enter your
|
397 |
)
|
398 |
-
caption_button = gr.Button("Caption Image")
|
399 |
-
with gr.TabItem('2. Add SEGA edit concepts', id=1):
|
|
|
400 |
# 1st SEGA concept
|
401 |
-
|
|
|
402 |
edit_concept_1 = gr.Textbox(
|
403 |
label="Edit Concept",
|
404 |
show_label=False,
|
405 |
-
max_lines=1,
|
406 |
placeholder="Enter your 1st edit prompt",
|
407 |
)
|
|
|
408 |
neg_guidance_1 = gr.Checkbox(
|
409 |
label='Negative Guidance')
|
410 |
|
411 |
# guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
412 |
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
413 |
# step=0.5, interactive=True)
|
414 |
-
|
415 |
|
416 |
add_1 = gr.Button('Add')
|
417 |
|
418 |
# 2nd SEGA concept
|
419 |
-
|
|
|
420 |
edit_concept_2 = gr.Textbox(
|
421 |
label="Edit Concept",
|
422 |
show_label=False,
|
423 |
max_lines=1,
|
424 |
placeholder="Enter your 2st edit prompt",
|
425 |
)
|
|
|
426 |
neg_guidance_2 = gr.Checkbox(
|
427 |
label='Negative Guidance',visible=True)
|
428 |
# guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
429 |
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
430 |
# step=0.5, interactive=True)
|
|
|
431 |
add_2 = gr.Button('Add')
|
432 |
|
433 |
# 3rd SEGA concept
|
434 |
-
|
|
|
435 |
edit_concept_3 = gr.Textbox(
|
436 |
label="Edit Concept",
|
437 |
show_label=False,
|
438 |
max_lines=1,
|
439 |
placeholder="Enter your 3rd edit prompt",
|
440 |
)
|
|
|
441 |
neg_guidance_3 = gr.Checkbox(
|
442 |
label='Negative Guidance',visible=True)
|
443 |
# guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
444 |
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
445 |
# step=0.5, interactive=True)
|
|
|
446 |
add_3 = gr.Button('Add')
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
-
|
452 |
add_concept_button = gr.Button("+")
|
453 |
|
454 |
|
455 |
with gr.Row():
|
456 |
run_button = gr.Button("Edit", visible=True)
|
457 |
-
|
458 |
-
clear_button = gr.Button("Clear", visible=True)
|
459 |
|
460 |
with gr.Accordion("Advanced Options", open=False):
|
461 |
with gr.Tabs() as tabs:
|
462 |
|
463 |
with gr.TabItem('General options', id=2):
|
464 |
with gr.Row():
|
465 |
-
with gr.Column():
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
with gr.Column():
|
|
|
473 |
skip = gr.Slider(minimum=0, maximum=60, value=36, label="Skip Steps", interactive=True)
|
474 |
tar_cfg_scale = gr.Slider(minimum=7, maximum=30,value=15, label=f"Guidance Scale", interactive=True)
|
|
|
|
|
475 |
|
476 |
with gr.TabItem('SEGA options', id=3) as sega_advanced_tab:
|
477 |
# 1st SEGA concept
|
@@ -499,15 +494,15 @@ with gr.Blocks(css="style.css") as demo:
|
|
499 |
value=DEFAULT_THRESHOLD, steps=0.01,
|
500 |
interactive=True)
|
501 |
|
502 |
-
caption_button.click(
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
)
|
507 |
|
508 |
-
add_1.click(fn = update_display_concept_1, inputs=[add_1, edit_concept_1], outputs=[box1, concept_1, concept_1, edit_concept_1, guidnace_scale_1, add_1])
|
509 |
-
add_2.click(fn = update_display_concept_2, inputs=[add_2, edit_concept_2], outputs=[box2, concept_2, concept_2, edit_concept_2, guidnace_scale_2, add_2])
|
510 |
-
add_3.click(fn = update_display_concept_3, inputs=[add_3, edit_concept_3], outputs=[box3, concept_3, concept_3, edit_concept_3, guidnace_scale_3, add_3])
|
511 |
|
512 |
|
513 |
add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
|
@@ -539,10 +534,10 @@ with gr.Blocks(css="style.css") as demo:
|
|
539 |
guidnace_scale_1,guidnace_scale_2,guidnace_scale_3,
|
540 |
warmup_1, warmup_2, warmup_3,
|
541 |
neg_guidance_1, neg_guidance_2, neg_guidance_3,
|
542 |
-
threshold_1, threshold_2, threshold_3
|
543 |
|
544 |
],
|
545 |
-
outputs=[sega_edited_image, reconstruct_button])
|
546 |
# .success(fn=update_gallery_display, inputs= [prev_output_image, sega_edited_image], outputs = [gallery, gallery, prev_output_image])
|
547 |
|
548 |
|
@@ -568,7 +563,9 @@ with gr.Blocks(css="style.css") as demo:
|
|
568 |
# outputs=[ddpm_edited_image, wts, zs, do_inversion],
|
569 |
outputs=[wts, zs, do_inversion, inversion_progress],
|
570 |
).then(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion],
|
571 |
-
outputs=[inversion_progress],queue=False).then(
|
|
|
|
|
572 |
lambda: reconstruct_button.update(visible=False),
|
573 |
outputs=[reconstruct_button]).then(
|
574 |
fn = reset_do_reconstruction,
|
@@ -615,15 +612,15 @@ with gr.Blocks(css="style.css") as demo:
|
|
615 |
clear_components = [input_image,ddpm_edited_image,ddpm_edited_image,sega_edited_image, do_inversion,
|
616 |
src_prompt, steps, src_cfg_scale, seed,
|
617 |
tar_prompt, skip, tar_cfg_scale, reconstruct_button,reconstruct_button,
|
618 |
-
edit_concept_1, guidnace_scale_1,guidnace_scale_1,warmup_1, threshold_1, neg_guidance_1, concept_1, concept_1,
|
619 |
-
edit_concept_2, guidnace_scale_2,guidnace_scale_2,warmup_2, threshold_2, neg_guidance_2, concept_2, concept_2, row2, row2_advanced,
|
620 |
edit_concept_3, guidnace_scale_3,guidnace_scale_3,warmup_3, threshold_3, neg_guidance_3, concept_3,concept_3, row3, row3_advanced ]
|
621 |
|
622 |
clear_components_output_vals = [None, None,ddpm_edited_image.update(visible=False), None, True,
|
623 |
"", DEFAULT_DIFFUSION_STEPS, DEFAULT_SOURCE_GUIDANCE_SCALE, DEFAULT_SEED,
|
624 |
"", DEFAULT_SKIP_STEPS, DEFAULT_TARGET_GUIDANCE_SCALE, reconstruct_button.update(value="Show Reconstruction"),reconstruct_button.update(visible=False),
|
625 |
"", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_1.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "", concept_1.update(visible=False),
|
626 |
-
"", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_2.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "", concept_2.update(visible=False), row2.update(visible=False), row2_advanced.update(visible=False),
|
627 |
"", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_3.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "",concept_3.update(visible=False), row3.update(visible=False), row3_advanced.update(visible=False)
|
628 |
]
|
629 |
|
@@ -640,11 +637,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
640 |
reconstruct_button],
|
641 |
outputs = [ddpm_edited_image,reconstruction, ddpm_edited_image, do_reconstruction, reconstruct_button])
|
642 |
|
643 |
-
|
644 |
-
edit_concept_1.change(fn=update_edit_concept, inputs = [concept_1, edit_concept_1, add_1], outputs = [concept_1])
|
645 |
-
edit_concept_2.change(fn=update_edit_concept, inputs = [concept_2, edit_concept_2, add_2], outputs = [concept_2])
|
646 |
-
edit_concept_3.change(fn=update_edit_concept, inputs = [concept_3, edit_concept_3, add_3], outputs = [concept_3])
|
647 |
-
|
648 |
randomize_seed.change(
|
649 |
fn = randomize_seed_fn,
|
650 |
inputs = [seed, randomize_seed],
|
|
|
130 |
guidnace_scale_1,guidnace_scale_2,guidnace_scale_3,
|
131 |
warmup_1, warmup_2, warmup_3,
|
132 |
neg_guidance_1, neg_guidance_2, neg_guidance_3,
|
133 |
+
threshold_1, threshold_2, threshold_3,
|
134 |
+
do_reconstruction,
|
135 |
+
reconstruction):
|
136 |
+
|
137 |
+
|
138 |
+
if edit_concept_1 != "" or edit_concept_2 != "" or edit_concept_3 != "":
|
139 |
+
editing_args = dict(
|
140 |
+
editing_prompt = [edit_concept_1,edit_concept_2,edit_concept_3],
|
141 |
+
reverse_editing_direction = [ neg_guidance_1, neg_guidance_2, neg_guidance_3,],
|
142 |
+
edit_warmup_steps=[warmup_1, warmup_2, warmup_3,],
|
143 |
+
edit_guidance_scale=[guidnace_scale_1,guidnace_scale_2,guidnace_scale_3],
|
144 |
+
edit_threshold=[threshold_1, threshold_2, threshold_3],
|
145 |
+
edit_momentum_scale=0.3,
|
146 |
+
edit_mom_beta=0.6,
|
147 |
+
eta=1,)
|
148 |
+
|
149 |
+
latnets = wts.value[skip].expand(1, -1, -1, -1)
|
150 |
+
sega_out = sem_pipe(prompt=tar_prompt, latents=latnets, guidance_scale = tar_cfg_scale,
|
151 |
+
num_images_per_prompt=1,
|
152 |
+
num_inference_steps=steps,
|
153 |
+
use_ddpm=True, wts=wts.value, zs=zs.value[skip:], **editing_args)
|
154 |
+
|
155 |
+
return sega_out.images[0], reconstruct_button.update(visible=True), do_reconstruction, reconstruction
|
156 |
+
|
157 |
+
else: # if sega concepts were not added, performs regular ddpm sampling
|
158 |
+
|
159 |
+
if do_reconstruction: # if ddpm sampling wasn't computed
|
160 |
+
pure_ddpm_img = sample(zs.value, wts.value, prompt_tar=tar_prompt, skip=skip, cfg_scale_tar=tar_cfg_scale)
|
161 |
+
reconstruction = gr.State(value=pure_ddpm_img)
|
162 |
+
do_reconstruction = False
|
163 |
+
return pure_ddpm_img, reconstruct_button.update(visible=False), do_reconstruction, reconstruction
|
164 |
+
|
165 |
+
return reconstruction, reconstruct_button.update(visible=False), do_reconstruction, reconstruction
|
166 |
+
|
167 |
|
168 |
def randomize_seed_fn(seed, randomize_seed):
|
169 |
if randomize_seed:
|
|
|
282 |
if sega_concepts_counter == 1:
|
283 |
return row2.update(visible=True), row2_advanced.update(visible=True), row3.update(visible=False), row3_advanced.update(visible=False), add_concept_button.update(visible=True), 2
|
284 |
else:
|
285 |
+
return row2.update(visible=True), row2_advanced.update(visible=True), row3.update(visible=True), row3_advanced.update(visible=True), add_concept_button.update(visible=False), 3
|
286 |
|
287 |
+
def update_display_concept_1(add_1, edit_concept_1, neg_guidance_1):
|
288 |
+
if add_1 == 'Add' and edit_concept_1 != "":
|
289 |
+
return box1.update(visible=True), edit_concept_1, concept_1.update(visible=True), edit_concept_1, guidnace_scale_1.update(visible=True), neg_guidance_1, "Clear"
|
290 |
else: # remove
|
291 |
+
return box1.update(visible=False),"", concept_1.update(visible=False), "", guidnace_scale_1.update(visible=False), False, "Add"
|
292 |
|
293 |
+
def update_display_concept_2(add_2, edit_concept_2, neg_guidance_2):
|
294 |
+
if add_2 == 'Add' and edit_concept_2 != "":
|
295 |
+
return box2.update(visible=True), edit_concept_2, concept_2.update(visible=True),edit_concept_2, guidnace_scale_2.update(visible=True), neg_guidance_2, "Clear"
|
296 |
else: # remove
|
297 |
+
return box2.update(visible=False),"", concept_2.update(visible=False), "", guidnace_scale_2.update(visible=False), False, "Add"
|
298 |
|
299 |
+
def update_display_concept_3(add_3, edit_concept_3, neg_guidance_3):
|
300 |
+
if add_3 == 'Add'and edit_concept_3 != "":
|
301 |
+
return box3.update(visible=True), edit_concept_3, concept_3.update(visible=True), edit_concept_3, guidnace_scale_3.update(visible=True), neg_guidance_3, "Clear"
|
302 |
else: # remove
|
303 |
+
return box3.update(visible=False), "", concept_3.update(visible=False), "", guidnace_scale_3.update(visible=False), False, "Add"
|
304 |
|
305 |
def display_editing_options(run_button, clear_button, sega_tab):
|
306 |
return run_button.update(visible=True), clear_button.update(visible=True), sega_tab.update(visible=True)
|
307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
# def update_gallery_display(prev_output_image, sega_edited_image):
|
309 |
# if prev_output_image is None:
|
310 |
# return sega_edited_image, gallery.update(visible=True), sega_edited_image
|
|
|
340 |
sega_concepts_counter = gr.State(1)
|
341 |
|
342 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
|
344 |
with gr.Row():
|
345 |
input_image = gr.Image(label="Input Image", interactive=True)
|
|
|
367 |
step=0.5, interactive=True,visible=False)
|
368 |
|
369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
with gr.Row():
|
371 |
inversion_progress = gr.Textbox(visible=False, label="Inversion progress")
|
372 |
|
373 |
+
# with gr.Tabs() as tabs:
|
374 |
+
# with gr.TabItem('1. Describe the desired output', id=0):
|
375 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
376 |
tar_prompt = gr.Textbox(
|
377 |
+
label="Image Description",
|
378 |
show_label=False,
|
379 |
+
max_lines=1, value="",
|
380 |
+
placeholder="Enter your target prompt",
|
381 |
)
|
382 |
+
# caption_button = gr.Button("Caption Image")
|
383 |
+
# with gr.TabItem('2. Add SEGA edit concepts', id=1):
|
384 |
+
intro_segs = gr.Markdown("Add SEGA Edit Concepts")
|
385 |
# 1st SEGA concept
|
386 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
387 |
+
with gr.Column(scale=3, min_width=100):
|
388 |
edit_concept_1 = gr.Textbox(
|
389 |
label="Edit Concept",
|
390 |
show_label=False,
|
391 |
+
max_lines=1, value="",
|
392 |
placeholder="Enter your 1st edit prompt",
|
393 |
)
|
394 |
+
with gr.Column(scale=1, min_width=100):
|
395 |
neg_guidance_1 = gr.Checkbox(
|
396 |
label='Negative Guidance')
|
397 |
|
398 |
# guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
399 |
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
400 |
# step=0.5, interactive=True)
|
401 |
+
with gr.Column(scale=1, min_width=100):
|
402 |
|
403 |
add_1 = gr.Button('Add')
|
404 |
|
405 |
# 2nd SEGA concept
|
406 |
+
with gr.Row(visible=False).style(equal_height=True) as row2:
|
407 |
+
with gr.Column(scale=3, min_width=100):
|
408 |
edit_concept_2 = gr.Textbox(
|
409 |
label="Edit Concept",
|
410 |
show_label=False,
|
411 |
max_lines=1,
|
412 |
placeholder="Enter your 2st edit prompt",
|
413 |
)
|
414 |
+
with gr.Column(scale=1, min_width=100):
|
415 |
neg_guidance_2 = gr.Checkbox(
|
416 |
label='Negative Guidance',visible=True)
|
417 |
# guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
418 |
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
419 |
# step=0.5, interactive=True)
|
420 |
+
with gr.Column(scale=1, min_width=100):
|
421 |
add_2 = gr.Button('Add')
|
422 |
|
423 |
# 3rd SEGA concept
|
424 |
+
with gr.Row(visible=False).style(equal_height=True) as row3:
|
425 |
+
with gr.Column(scale=3, min_width=100):
|
426 |
edit_concept_3 = gr.Textbox(
|
427 |
label="Edit Concept",
|
428 |
show_label=False,
|
429 |
max_lines=1,
|
430 |
placeholder="Enter your 3rd edit prompt",
|
431 |
)
|
432 |
+
with gr.Column(scale=1, min_width=100):
|
433 |
neg_guidance_3 = gr.Checkbox(
|
434 |
label='Negative Guidance',visible=True)
|
435 |
# guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
436 |
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
437 |
# step=0.5, interactive=True)
|
438 |
+
with gr.Column(scale=1, min_width=100):
|
439 |
add_3 = gr.Button('Add')
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
445 |
add_concept_button = gr.Button("+")
|
446 |
|
447 |
|
448 |
with gr.Row():
|
449 |
run_button = gr.Button("Edit", visible=True)
|
450 |
+
|
|
|
451 |
|
452 |
with gr.Accordion("Advanced Options", open=False):
|
453 |
with gr.Tabs() as tabs:
|
454 |
|
455 |
with gr.TabItem('General options', id=2):
|
456 |
with gr.Row():
|
457 |
+
with gr.Column(min_width=100):
|
458 |
+
clear_button = gr.Button("Clear", visible=True)
|
459 |
+
src_prompt = gr.Textbox(lines=1, label="Source Prompt", interactive=True, placeholder="")
|
460 |
+
steps = gr.Number(value=100, precision=0, label="Num Diffusion Steps", interactive=True)
|
461 |
+
src_cfg_scale = gr.Number(value=3.5, label=f"Source Guidance Scale", interactive=True)
|
462 |
+
|
463 |
+
|
464 |
+
with gr.Column(min_width=100):
|
465 |
+
reconstruct_button = gr.Button("Show Reconstruction", visible=False)
|
466 |
skip = gr.Slider(minimum=0, maximum=60, value=36, label="Skip Steps", interactive=True)
|
467 |
tar_cfg_scale = gr.Slider(minimum=7, maximum=30,value=15, label=f"Guidance Scale", interactive=True)
|
468 |
+
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
469 |
+
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
470 |
|
471 |
with gr.TabItem('SEGA options', id=3) as sega_advanced_tab:
|
472 |
# 1st SEGA concept
|
|
|
494 |
value=DEFAULT_THRESHOLD, steps=0.01,
|
495 |
interactive=True)
|
496 |
|
497 |
+
# caption_button.click(
|
498 |
+
# fn = caption_image,
|
499 |
+
# inputs = [input_image],
|
500 |
+
# outputs = [tar_prompt]
|
501 |
+
# )
|
502 |
|
503 |
+
add_1.click(fn = update_display_concept_1, inputs=[add_1, edit_concept_1, neg_guidance_1], outputs=[box1, concept_1, concept_1, edit_concept_1, guidnace_scale_1,neg_guidance_1, add_1])
|
504 |
+
add_2.click(fn = update_display_concept_2, inputs=[add_2, edit_concept_2, neg_guidance_2], outputs=[box2, concept_2, concept_2, edit_concept_2, guidnace_scale_2,neg_guidance_2, add_2])
|
505 |
+
add_3.click(fn = update_display_concept_3, inputs=[add_3, edit_concept_3, neg_guidance_3], outputs=[box3, concept_3, concept_3, edit_concept_3, guidnace_scale_3,neg_guidance_3, add_3])
|
506 |
|
507 |
|
508 |
add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
|
|
|
534 |
guidnace_scale_1,guidnace_scale_2,guidnace_scale_3,
|
535 |
warmup_1, warmup_2, warmup_3,
|
536 |
neg_guidance_1, neg_guidance_2, neg_guidance_3,
|
537 |
+
threshold_1, threshold_2, threshold_3, do_reconstruction, reconstruction
|
538 |
|
539 |
],
|
540 |
+
outputs=[sega_edited_image, reconstruct_button, do_reconstruction, reconstruction])
|
541 |
# .success(fn=update_gallery_display, inputs= [prev_output_image, sega_edited_image], outputs = [gallery, gallery, prev_output_image])
|
542 |
|
543 |
|
|
|
563 |
# outputs=[ddpm_edited_image, wts, zs, do_inversion],
|
564 |
outputs=[wts, zs, do_inversion, inversion_progress],
|
565 |
).then(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion],
|
566 |
+
outputs=[inversion_progress],queue=False).then(fn = caption_image,
|
567 |
+
inputs = [input_image],
|
568 |
+
outputs = [tar_prompt]).then(
|
569 |
lambda: reconstruct_button.update(visible=False),
|
570 |
outputs=[reconstruct_button]).then(
|
571 |
fn = reset_do_reconstruction,
|
|
|
612 |
clear_components = [input_image,ddpm_edited_image,ddpm_edited_image,sega_edited_image, do_inversion,
|
613 |
src_prompt, steps, src_cfg_scale, seed,
|
614 |
tar_prompt, skip, tar_cfg_scale, reconstruct_button,reconstruct_button,
|
615 |
+
edit_concept_1, guidnace_scale_1,guidnace_scale_1,warmup_1, threshold_1, neg_guidance_1, concept_1, concept_1,
|
616 |
+
edit_concept_2, guidnace_scale_2,guidnace_scale_2,warmup_2, threshold_2, neg_guidance_2, concept_2, concept_2, row2, row2_advanced,
|
617 |
edit_concept_3, guidnace_scale_3,guidnace_scale_3,warmup_3, threshold_3, neg_guidance_3, concept_3,concept_3, row3, row3_advanced ]
|
618 |
|
619 |
clear_components_output_vals = [None, None,ddpm_edited_image.update(visible=False), None, True,
|
620 |
"", DEFAULT_DIFFUSION_STEPS, DEFAULT_SOURCE_GUIDANCE_SCALE, DEFAULT_SEED,
|
621 |
"", DEFAULT_SKIP_STEPS, DEFAULT_TARGET_GUIDANCE_SCALE, reconstruct_button.update(value="Show Reconstruction"),reconstruct_button.update(visible=False),
|
622 |
"", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_1.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "", concept_1.update(visible=False),
|
623 |
+
"", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_2.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "", concept_2.update(visible=False), row2.update(visible=False), row2_advanced.update(visible=False),
|
624 |
"", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_3.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "",concept_3.update(visible=False), row3.update(visible=False), row3_advanced.update(visible=False)
|
625 |
]
|
626 |
|
|
|
637 |
reconstruct_button],
|
638 |
outputs = [ddpm_edited_image,reconstruction, ddpm_edited_image, do_reconstruction, reconstruct_button])
|
639 |
|
|
|
|
|
|
|
|
|
|
|
640 |
randomize_seed.change(
|
641 |
fn = randomize_seed_fn,
|
642 |
inputs = [seed, randomize_seed],
|