Linoy Tsaban commited on
Commit
9e7d73a
1 Parent(s): da5eff7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -48
app.py CHANGED
@@ -318,25 +318,31 @@ with gr.Blocks(css="style.css") as demo:
318
  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
319
 
320
  def update_display_concept_1(add_1, edit_concept_1, neg_guidance_1):
321
- guidance_scale_info = "How strongly the concept should be included in the image"
322
- if add_1 == 'Include' or add_1 == 'Remove' and edit_concept_1 != "":
323
  if neg_guidance_1:
324
- guidance_scale_info = "How strongly the concept should be removed from the image"
325
- 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", gr.update(interactive=False), gr.update(interactive=False)
326
  else: # remove
327
- return box1.update(visible=False),"",concept_1.update(visible=False), "", guidnace_scale_1.update(visible=False), False, "Include", gr.update(interactive=True), gr.update(interactive=True)
328
 
329
  def update_display_concept_2(add_2, edit_concept_2, neg_guidance_2):
330
- if add_2 == 'Include' or add_2 == 'Remove' and edit_concept_2 != "":
331
- 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", gr.update(interactive=False), gr.update(interactive=False)
 
 
 
332
  else: # remove
333
- return box2.update(visible=False),"", concept_2.update(visible=False), "", guidnace_scale_2.update(visible=False), False, "Include", gr.update(interactive=True), gr.update(interactive=True)
334
 
335
  def update_display_concept_3(add_3, edit_concept_3, neg_guidance_3):
336
- if add_3 == 'Include'or add_3 == 'Remove' and edit_concept_3 != "":
337
- 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", gr.update(interactive=False), gr.update(interactive=False)
 
 
 
338
  else: # remove
339
- return box3.update(visible=False), "", concept_3.update(visible=False), "", guidnace_scale_3.update(visible=False), False, "Include", gr.update(interactive=True), gr.update(interactive=True)
340
 
341
  def display_editing_options(run_button, clear_button, sega_tab):
342
  return run_button.update(visible=True), clear_button.update(visible=True), sega_tab.update(visible=True)
@@ -351,17 +357,24 @@ with gr.Blocks(css="style.css") as demo:
351
  return gr.update(interactive=False), gr.update(interactive=False)
352
  else:
353
  return gr.update(interactive=True), gr.update(interactive=True)
354
-
355
- # def update_gallery_display(prev_output_image, sega_edited_image):
356
- # if prev_output_image is None:
357
- # return sega_edited_image, gallery.update(visible=True), sega_edited_image
358
- # else:
359
- # return prev_output_image, gallery.update(visible=True), sega_edited_image
360
-
 
 
 
 
361
 
362
 
363
  def reset_do_inversion():
364
- return True
 
 
 
365
 
366
  def reset_do_reconstruction():
367
  do_reconstruction = True
@@ -373,8 +386,7 @@ with gr.Blocks(css="style.css") as demo:
373
  else:
374
  return inversion_progress.update(visible=False)
375
 
376
- def undo():
377
- return
378
 
379
 
380
  gr.HTML(intro)
@@ -419,8 +431,7 @@ with gr.Blocks(css="style.css") as demo:
419
  with gr.Row():
420
  inversion_progress = gr.Textbox(visible=False, label="Inversion progress")
421
 
422
- # with gr.Tabs() as tabs:
423
- # with gr.TabItem('1. Describe the desired output', id=0):
424
  with gr.Row().style(mobile_collapse=False, equal_height=True):
425
  tar_prompt = gr.Textbox(
426
  label="Image Description",
@@ -428,12 +439,11 @@ with gr.Blocks(css="style.css") as demo:
428
  max_lines=1, value="",
429
  placeholder="Enter your target prompt",
430
  )
431
- # caption_button = gr.Button("Caption Image")
432
- # with gr.TabItem('2. Add SEGA edit concepts', id=1):
433
  with gr.Box():
434
  intro_segs = gr.Markdown("Add/Remove New Concepts to your Image")
435
  # 1st SEGA concept
436
- with gr.Row().style(mobile_collapse=False, equal_height=True):
437
  with gr.Column(scale=3, min_width=100):
438
  edit_concept_1 = gr.Textbox(
439
  label="Edit Concept",
@@ -444,13 +454,14 @@ with gr.Blocks(css="style.css") as demo:
444
  with gr.Column(scale=1, min_width=100):
445
  neg_guidance_1 = gr.Checkbox(
446
  label='Remove Concept?')
 
447
 
448
- # guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
449
- # value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
450
- # step=0.5, interactive=True)
451
  with gr.Column(scale=1, min_width=100):
452
-
453
  add_1 = gr.Button('Include')
 
454
 
455
  # 2nd SEGA concept
456
  with gr.Row(visible=False).style(equal_height=True) as row2:
@@ -464,9 +475,8 @@ with gr.Blocks(css="style.css") as demo:
464
  with gr.Column(scale=1, min_width=100):
465
  neg_guidance_2 = gr.Checkbox(
466
  label='Remove Concept?',visible=True)
467
- # guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
468
- # value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
469
- # step=0.5, interactive=True)
470
  with gr.Column(scale=1, min_width=100):
471
  add_2 = gr.Button('Include')
472
 
@@ -481,10 +491,8 @@ with gr.Blocks(css="style.css") as demo:
481
  )
482
  with gr.Column(scale=1, min_width=100):
483
  neg_guidance_3 = gr.Checkbox(
484
- label='Remove Concept?',visible=True)
485
- # guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
486
- # value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
487
- # step=0.5, interactive=True)
488
  with gr.Column(scale=1, min_width=100):
489
  add_3 = gr.Button('Include')
490
 
@@ -552,9 +560,9 @@ with gr.Blocks(css="style.css") as demo:
552
  neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
553
  neg_guidance_2.change(fn = update_label, inputs=[neg_guidance_2], outputs=[add_2])
554
  neg_guidance_3.change(fn = update_label, inputs=[neg_guidance_3], outputs=[add_3])
555
- 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, edit_concept_1,neg_guidance_1 ])
556
- 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, edit_concept_2,neg_guidance_2 ])
557
- 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, edit_concept_3, neg_guidance_3])
558
 
559
  add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
560
  outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)
@@ -594,7 +602,7 @@ with gr.Blocks(css="style.css") as demo:
594
 
595
 
596
  # Automatically start inverting upon input_image change
597
- input_image.upload(
598
  fn = reset_do_inversion,
599
  inputs = [input_image],
600
  outputs = [do_inversion],
@@ -659,21 +667,23 @@ with gr.Blocks(css="style.css") as demo:
659
  fn = reset_do_reconstruction,
660
  outputs = [do_reconstruction], queue = False)
661
 
662
-
 
 
663
 
664
  clear_components = [input_image,ddpm_edited_image,ddpm_edited_image,sega_edited_image, do_inversion,
665
  src_prompt, steps, src_cfg_scale, seed,
666
  tar_prompt, skip, tar_cfg_scale, reconstruct_button,reconstruct_button,
667
- edit_concept_1, guidnace_scale_1,guidnace_scale_1,warmup_1, threshold_1, neg_guidance_1, concept_1, concept_1,
668
- edit_concept_2, guidnace_scale_2,guidnace_scale_2,warmup_2, threshold_2, neg_guidance_2, concept_2, concept_2, row2, row2_advanced,
669
- edit_concept_3, guidnace_scale_3,guidnace_scale_3,warmup_3, threshold_3, neg_guidance_3, concept_3,concept_3, row3, row3_advanced ]
670
 
671
  clear_components_output_vals = [None, None,ddpm_edited_image.update(visible=False), None, True,
672
  "", DEFAULT_DIFFUSION_STEPS, DEFAULT_SOURCE_GUIDANCE_SCALE, DEFAULT_SEED,
673
  "", DEFAULT_SKIP_STEPS, DEFAULT_TARGET_GUIDANCE_SCALE, reconstruct_button.update(value="Show Reconstruction"),reconstruct_button.update(visible=False),
674
- "", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_1.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "", concept_1.update(visible=False),
675
- "", 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),
676
- "", 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)
677
  ]
678
 
679
 
@@ -694,6 +704,8 @@ with gr.Blocks(css="style.css") as demo:
694
  inputs = [seed, randomize_seed],
695
  outputs = [seed],
696
  queue = False)
 
 
697
 
698
  gr.Examples(
699
  label='Examples',
 
318
  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
319
 
320
  def update_display_concept_1(add_1, edit_concept_1, neg_guidance_1):
321
+ guidance_scale_label = "Concept Guidance Scale"
322
+ if (add_1 == 'Include' or add_1 == 'Remove') and edit_concept_1 != "":
323
  if neg_guidance_1:
324
+ guidance_scale_label = "Negative Guidance Scale"
325
+ 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", gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False),gr.update(label = guidance_scale_label)
326
  else: # remove
327
+ return box1.update(visible=False),"",concept_1.update(visible=False), "", guidnace_scale_1.update(visible=False), False, "Include", gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True),gr.update(label = guidance_scale_label)
328
 
329
  def update_display_concept_2(add_2, edit_concept_2, neg_guidance_2):
330
+ guidance_scale_label = "Concept Guidance Scale"
331
+ if (add_2 == 'Include' or add_2 == 'Remove') and edit_concept_2 != "":
332
+ if neg_guidance_1:
333
+ guidance_scale_label = "Negative Guidance Scale"
334
+ 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", gr.update(interactive=False), gr.update(interactive=False),gr.update(interactive=False),gr.update(label = guidance_scale_label)
335
  else: # remove
336
+ return box2.update(visible=False),"", concept_2.update(visible=False), "", guidnace_scale_2.update(visible=False), False, "Include", gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True),gr.update(label = guidance_scale_label)
337
 
338
  def update_display_concept_3(add_3, edit_concept_3, neg_guidance_3):
339
+ guidance_scale_label = "Concept Guidance Scale"
340
+ if (add_3 == 'Include'or add_3 == 'Remove') and edit_concept_3 != "":
341
+ if neg_guidance_1:
342
+ guidance_scale_label = "Negative Guidance Scale"
343
+ 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", gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False),gr.update(label = guidance_scale_label)
344
  else: # remove
345
+ return box3.update(visible=False), "", concept_3.update(visible=False), "", guidnace_scale_3.update(visible=False), False, "Include", gr.update(interactive=True), gr.update(interactive=True),gr.update(interactive=True),gr.update(label = guidance_scale_label)
346
 
347
  def display_editing_options(run_button, clear_button, sega_tab):
348
  return run_button.update(visible=True), clear_button.update(visible=True), sega_tab.update(visible=True)
 
357
  return gr.update(interactive=False), gr.update(interactive=False)
358
  else:
359
  return gr.update(interactive=True), gr.update(interactive=True)
360
+
361
+
362
+ def update_dropdown_parms(dropdown):
363
+ if dropdown == 'default':
364
+ return DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD
365
+ elif dropdown =='style':
366
+ return STYLE_SEGA_CONCEPT_GUIDANCE_SCALE,STYLE_WARMUP_STEPS, STYLE_THRESHOLD
367
+ elif dropdown =='object':
368
+ return OBJECT_SEGA_CONCEPT_GUIDANCE_SCALE,OBJECT_WARMUP_STEPS, OBJECT_THRESHOLD
369
+ elif dropdown =='facial':
370
+ return FACE_SEGA_CONCEPT_GUIDANCE_SCALE,FACE_WARMUP_STEPS, FACE_THRESHOLD
371
 
372
 
373
  def reset_do_inversion():
374
+ if not input_image is None:
375
+ return True
376
+ else:
377
+ return False
378
 
379
  def reset_do_reconstruction():
380
  do_reconstruction = True
 
386
  else:
387
  return inversion_progress.update(visible=False)
388
 
389
+
 
390
 
391
 
392
  gr.HTML(intro)
 
431
  with gr.Row():
432
  inversion_progress = gr.Textbox(visible=False, label="Inversion progress")
433
 
434
+
 
435
  with gr.Row().style(mobile_collapse=False, equal_height=True):
436
  tar_prompt = gr.Textbox(
437
  label="Image Description",
 
439
  max_lines=1, value="",
440
  placeholder="Enter your target prompt",
441
  )
442
+
 
443
  with gr.Box():
444
  intro_segs = gr.Markdown("Add/Remove New Concepts to your Image")
445
  # 1st SEGA concept
446
+ with gr.Row().style(mobile_collapse=False):
447
  with gr.Column(scale=3, min_width=100):
448
  edit_concept_1 = gr.Textbox(
449
  label="Edit Concept",
 
454
  with gr.Column(scale=1, min_width=100):
455
  neg_guidance_1 = gr.Checkbox(
456
  label='Remove Concept?')
457
+ dropdown1 = gr.Dropdown(label = "Edit Type", value ='default' , choices=['default','style', 'object', 'facial'])
458
 
459
+
460
+
461
+
462
  with gr.Column(scale=1, min_width=100):
 
463
  add_1 = gr.Button('Include')
464
+
465
 
466
  # 2nd SEGA concept
467
  with gr.Row(visible=False).style(equal_height=True) as row2:
 
475
  with gr.Column(scale=1, min_width=100):
476
  neg_guidance_2 = gr.Checkbox(
477
  label='Remove Concept?',visible=True)
478
+ dropdown2 = gr.Dropdown(label = "Edit Type", value ='default' , choices=['default','style', 'object', 'facial'])
479
+
 
480
  with gr.Column(scale=1, min_width=100):
481
  add_2 = gr.Button('Include')
482
 
 
491
  )
492
  with gr.Column(scale=1, min_width=100):
493
  neg_guidance_3 = gr.Checkbox(
494
+ label='Remove Concept?',visible=True)
495
+ dropdown3 = gr.Dropdown(label = "Edit Type", value ='default' , choices=['default','style', 'object', 'facial'])
 
 
496
  with gr.Column(scale=1, min_width=100):
497
  add_3 = gr.Button('Include')
498
 
 
560
  neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
561
  neg_guidance_2.change(fn = update_label, inputs=[neg_guidance_2], outputs=[add_2])
562
  neg_guidance_3.change(fn = update_label, inputs=[neg_guidance_3], outputs=[add_3])
563
+ 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, edit_concept_1,neg_guidance_1, dropdown1, guidnace_scale_1])
564
+ 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, edit_concept_2,neg_guidance_2 , dropdown2,guidnace_scale_2])
565
+ 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, edit_concept_3, neg_guidance_3, dropdown3, guidnace_scale_3])
566
 
567
  add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
568
  outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)
 
602
 
603
 
604
  # Automatically start inverting upon input_image change
605
+ input_image.change(
606
  fn = reset_do_inversion,
607
  inputs = [input_image],
608
  outputs = [do_inversion],
 
667
  fn = reset_do_reconstruction,
668
  outputs = [do_reconstruction], queue = False)
669
 
670
+ dropdown1.change(fn=update_dropdown_parms, inputs = [dropdown1], outputs = [guidnace_scale_1,warmup_1, threshold_1])
671
+ dropdown2.change(fn=update_dropdown_parms, inputs = [dropdown2], outputs = [guidnace_scale_2,warmup_2, threshold_2])
672
+ dropdown3.change(fn=update_dropdown_parms, inputs = [dropdown3], outputs = [guidnace_scale_3,warmup_3, threshold_3])
673
 
674
  clear_components = [input_image,ddpm_edited_image,ddpm_edited_image,sega_edited_image, do_inversion,
675
  src_prompt, steps, src_cfg_scale, seed,
676
  tar_prompt, skip, tar_cfg_scale, reconstruct_button,reconstruct_button,
677
+ edit_concept_1, guidnace_scale_1,guidnace_scale_1,warmup_1, threshold_1, neg_guidance_1,dropdown1, concept_1, concept_1,
678
+ edit_concept_2, guidnace_scale_2,guidnace_scale_2,warmup_2, threshold_2, neg_guidance_2,dropdown2, concept_2, concept_2, row2, row2_advanced,
679
+ edit_concept_3, guidnace_scale_3,guidnace_scale_3,warmup_3, threshold_3, neg_guidance_3,dropdown3, concept_3,concept_3, row3, row3_advanced ]
680
 
681
  clear_components_output_vals = [None, None,ddpm_edited_image.update(visible=False), None, True,
682
  "", DEFAULT_DIFFUSION_STEPS, DEFAULT_SOURCE_GUIDANCE_SCALE, DEFAULT_SEED,
683
  "", DEFAULT_SKIP_STEPS, DEFAULT_TARGET_GUIDANCE_SCALE, reconstruct_button.update(value="Show Reconstruction"),reconstruct_button.update(visible=False),
684
+ "", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_1.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "","default", concept_1.update(visible=False),
685
+ "", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_2.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "","default", concept_2.update(visible=False), row2.update(visible=False), row2_advanced.update(visible=False),
686
+ "", DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,guidnace_scale_3.update(visible=False), DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD, DEFAULT_NEGATIVE_GUIDANCE, "","default",concept_3.update(visible=False), row3.update(visible=False), row3_advanced.update(visible=False)
687
  ]
688
 
689
 
 
704
  inputs = [seed, randomize_seed],
705
  outputs = [seed],
706
  queue = False)
707
+
708
+
709
 
710
  gr.Examples(
711
  label='Examples',