Linoy Tsaban commited on
Commit
7ddbfb5
1 Parent(s): 444b5ce

Update app.py

Browse files

bug fixes + interactivity disabled when a concept is added

Files changed (1) hide show
  1. app.py +30 -19
app.py CHANGED
@@ -171,11 +171,6 @@ def randomize_seed_fn(seed, randomize_seed):
171
  torch.manual_seed(seed)
172
  return seed
173
 
174
- def update_label(check_negative):
175
- if(check_negative):
176
- return gr.update(value="Remove")
177
- else:
178
- return gr.update(value="Include")
179
 
180
 
181
 
@@ -287,6 +282,7 @@ help_text = """
287
 
288
  with gr.Blocks(css="style.css") as demo:
289
 
 
290
  def add_concept(sega_concepts_counter):
291
  if sega_concepts_counter == 1:
292
  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
@@ -294,25 +290,39 @@ with gr.Blocks(css="style.css") as demo:
294
  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
295
 
296
  def update_display_concept_1(add_1, edit_concept_1, neg_guidance_1):
297
- if add_1 == 'Include' and edit_concept_1 != "":
298
- 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"
 
 
 
299
  else: # remove
300
- return box1.update(visible=False),"", concept_1.update(visible=False), "", guidnace_scale_1.update(visible=False), False, "Add"
301
 
302
  def update_display_concept_2(add_2, edit_concept_2, neg_guidance_2):
303
- if add_2 == 'Include' and edit_concept_2 != "":
304
- 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"
305
  else: # remove
306
- return box2.update(visible=False),"", concept_2.update(visible=False), "", guidnace_scale_2.update(visible=False), False, "Add"
307
 
308
  def update_display_concept_3(add_3, edit_concept_3, neg_guidance_3):
309
- if add_3 == 'Include'and edit_concept_3 != "":
310
- 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"
311
  else: # remove
312
- return box3.update(visible=False), "", concept_3.update(visible=False), "", guidnace_scale_3.update(visible=False), False, "Add"
313
 
314
  def display_editing_options(run_button, clear_button, sega_tab):
315
  return run_button.update(visible=True), clear_button.update(visible=True), sega_tab.update(visible=True)
 
 
 
 
 
 
 
 
 
 
 
316
 
317
  # def update_gallery_display(prev_output_image, sega_edited_image):
318
  # if prev_output_image is None:
@@ -394,7 +404,7 @@ with gr.Blocks(css="style.css") as demo:
394
  # caption_button = gr.Button("Caption Image")
395
  # with gr.TabItem('2. Add SEGA edit concepts', id=1):
396
  with gr.Box():
397
- intro_segs = gr.Markdown("Add/Remove New Concepts from your Image")
398
  # 1st SEGA concept
399
  with gr.Row().style(mobile_collapse=False, equal_height=True):
400
  with gr.Column(scale=3, min_width=100):
@@ -513,10 +523,11 @@ with gr.Blocks(css="style.css") as demo:
513
  # outputs = [tar_prompt]
514
  # )
515
  neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
516
- 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])
517
- 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])
518
- 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])
519
-
 
520
 
521
  add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
522
  outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)
 
171
  torch.manual_seed(seed)
172
  return seed
173
 
 
 
 
 
 
174
 
175
 
176
 
 
282
 
283
  with gr.Blocks(css="style.css") as demo:
284
 
285
+
286
  def add_concept(sega_concepts_counter):
287
  if sega_concepts_counter == 1:
288
  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
 
290
  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
291
 
292
  def update_display_concept_1(add_1, edit_concept_1, neg_guidance_1):
293
+ guidance_scale_info = "How strongly the concept should be included in the image"
294
+ if add_1 == 'Include' or add_1 == 'Remove' and edit_concept_1 != "":
295
+ if neg_guidance_1:
296
+ guidance_scale_info = "How strongly the concept should be removed from the image"
297
+ 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)
298
  else: # remove
299
+ 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)
300
 
301
  def update_display_concept_2(add_2, edit_concept_2, neg_guidance_2):
302
+ if add_2 == 'Include' or add_2 == 'Remove' and edit_concept_2 != "":
303
+ 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)
304
  else: # remove
305
+ 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)
306
 
307
  def update_display_concept_3(add_3, edit_concept_3, neg_guidance_3):
308
+ if add_3 == 'Include'or add_3 == 'Remove' and edit_concept_3 != "":
309
+ 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)
310
  else: # remove
311
+ 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)
312
 
313
  def display_editing_options(run_button, clear_button, sega_tab):
314
  return run_button.update(visible=True), clear_button.update(visible=True), sega_tab.update(visible=True)
315
+
316
+ def update_label(neg_gudiance, add_button_label):
317
+ if (neg_gudiance):
318
+ return "Remove"
319
+ else:
320
+ return "Include"
321
+ def update_interactive_mode(add_button_label):
322
+ if add_button_label == "Clear":
323
+ return gr.update(interactive=False), gr.update(interactive=False)
324
+ else:
325
+ return gr.update(interactive=True), gr.update(interactive=True)
326
 
327
  # def update_gallery_display(prev_output_image, sega_edited_image):
328
  # if prev_output_image is None:
 
404
  # caption_button = gr.Button("Caption Image")
405
  # with gr.TabItem('2. Add SEGA edit concepts', id=1):
406
  with gr.Box():
407
+ intro_segs = gr.Markdown("Add/Remove New Concepts to your Image")
408
  # 1st SEGA concept
409
  with gr.Row().style(mobile_collapse=False, equal_height=True):
410
  with gr.Column(scale=3, min_width=100):
 
523
  # outputs = [tar_prompt]
524
  # )
525
  neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
526
+ neg_guidance_2.change(fn = update_label, inputs=[neg_guidance_2], outputs=[add_2])
527
+ neg_guidance_3.change(fn = update_label, inputs=[neg_guidance_3], outputs=[add_3])
528
+ 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 ])
529
+ 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 ])
530
+ 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])
531
 
532
  add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
533
  outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)