Linoy Tsaban commited on
Commit
8575e70
1 Parent(s): c2870fd

Update app.py

Browse files

changed default value for SEGA edit_momentum_scale to 0.3

Files changed (1) hide show
  1. app.py +18 -27
app.py CHANGED
@@ -14,7 +14,6 @@ import re
14
 
15
 
16
 
17
-
18
  def invert(x0, prompt_src="", num_diffusion_steps=100, cfg_scale_src = 3.5, eta = 1):
19
 
20
  # inverts a real image according to Algorihm 1 in https://arxiv.org/pdf/2304.06140.pdf,
@@ -185,7 +184,7 @@ def edit(input_image,
185
  edit_warmup_steps=[warmup_1, warmup_2, warmup_3,],
186
  edit_guidance_scale=[guidnace_scale_1,guidnace_scale_2,guidnace_scale_3],
187
  edit_threshold=[threshold_1, threshold_2, threshold_3],
188
- edit_momentum_scale=0.5,
189
  edit_mom_beta=0.6,
190
  eta=1,
191
  )
@@ -296,9 +295,8 @@ with gr.Blocks(css='style.css') as demo:
296
  placeholder="Enter your 1st edit prompt",
297
  )
298
  with gr.TabItem('2. Add SEGA edit concepts', id=1):
299
- # with gr.Group():
300
  with gr.Row().style(mobile_collapse=False, equal_height=True):
301
- # tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
302
  neg_guidance_1 = gr.Checkbox(
303
  label='Negative Guidance')
304
  warmup_1 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=1, step=1, interactive=True)
@@ -310,10 +308,9 @@ with gr.Blocks(css='style.css') as demo:
310
  max_lines=1,
311
  placeholder="Enter your 1st edit prompt",
312
  )
313
-
 
314
  with gr.Row(visible=False) as row2:
315
-
316
- # tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
317
  neg_guidance_2 = gr.Checkbox(
318
  label='Negative Guidance',visible=True)
319
  warmup_2 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=1, step=1, visible=True,interactive=True)
@@ -325,10 +322,8 @@ with gr.Blocks(css='style.css') as demo:
325
  max_lines=1,
326
  placeholder="Enter your 2st edit prompt",
327
  )
328
-
329
  with gr.Row(visible=False) as row3:
330
-
331
- # tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
332
  neg_guidance_3 = gr.Checkbox(
333
  label='Negative Guidance',visible=True)
334
  warmup_3 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=1, step=1, visible=True,interactive=True)
@@ -349,8 +344,6 @@ with gr.Blocks(css='style.css') as demo:
349
  with gr.Column(scale=1, min_width=100):
350
  run_button = gr.Button("Run")
351
  reconstruct_button = gr.Button("Show me the reconstruction", visible=False)
352
- # with gr.Column(scale=1, min_width=100):
353
- # edit_button = gr.Button("Edit")
354
 
355
  with gr.Accordion("Advanced Options", open=False):
356
  with gr.Row():
@@ -369,23 +362,11 @@ with gr.Blocks(css='style.css') as demo:
369
  with gr.Accordion("Help", open=False):
370
  gr.Markdown(help_text)
371
 
372
-
373
 
374
  add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
375
  outputs= [row2, row3, add_concept_button, sega_concepts_counter], queue = False)
376
 
377
- reconstruct_button.click(
378
- fn = show_reconstruction,
379
- outputs = [ddpm_edited_image]
380
- ).then(
381
- fn = reconstruct,
382
- inputs = [tar_prompt,
383
- tar_cfg_scale,
384
- skip,
385
- wts, zs],
386
- outputs = [ddpm_edited_image]
387
- )
388
-
389
 
390
  run_button.click(
391
  fn = randomize_seed_fn,
@@ -405,7 +386,6 @@ with gr.Blocks(css='style.css') as demo:
405
  tar_cfg_scale
406
  ],
407
  outputs=[wts, zs, do_inversion],
408
-
409
  ).success(
410
  fn=edit,
411
  inputs=[input_image,
@@ -427,7 +407,18 @@ with gr.Blocks(css='style.css') as demo:
427
  outputs = [reconstruct_button]
428
  )
429
 
430
-
 
 
 
 
 
 
 
 
 
 
 
431
 
432
  # Automatically start inverting upon input_image change
433
  input_image.change(
 
14
 
15
 
16
 
 
17
  def invert(x0, prompt_src="", num_diffusion_steps=100, cfg_scale_src = 3.5, eta = 1):
18
 
19
  # inverts a real image according to Algorihm 1 in https://arxiv.org/pdf/2304.06140.pdf,
 
184
  edit_warmup_steps=[warmup_1, warmup_2, warmup_3,],
185
  edit_guidance_scale=[guidnace_scale_1,guidnace_scale_2,guidnace_scale_3],
186
  edit_threshold=[threshold_1, threshold_2, threshold_3],
187
+ edit_momentum_scale=0.3,
188
  edit_mom_beta=0.6,
189
  eta=1,
190
  )
 
295
  placeholder="Enter your 1st edit prompt",
296
  )
297
  with gr.TabItem('2. Add SEGA edit concepts', id=1):
298
+ # 1st SEGA concept
299
  with gr.Row().style(mobile_collapse=False, equal_height=True):
 
300
  neg_guidance_1 = gr.Checkbox(
301
  label='Negative Guidance')
302
  warmup_1 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=1, step=1, interactive=True)
 
308
  max_lines=1,
309
  placeholder="Enter your 1st edit prompt",
310
  )
311
+
312
+ # 2nd SEGA concept
313
  with gr.Row(visible=False) as row2:
 
 
314
  neg_guidance_2 = gr.Checkbox(
315
  label='Negative Guidance',visible=True)
316
  warmup_2 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=1, step=1, visible=True,interactive=True)
 
322
  max_lines=1,
323
  placeholder="Enter your 2st edit prompt",
324
  )
325
+ # 3rd SEGA concept
326
  with gr.Row(visible=False) as row3:
 
 
327
  neg_guidance_3 = gr.Checkbox(
328
  label='Negative Guidance',visible=True)
329
  warmup_3 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=1, step=1, visible=True,interactive=True)
 
344
  with gr.Column(scale=1, min_width=100):
345
  run_button = gr.Button("Run")
346
  reconstruct_button = gr.Button("Show me the reconstruction", visible=False)
 
 
347
 
348
  with gr.Accordion("Advanced Options", open=False):
349
  with gr.Row():
 
362
  with gr.Accordion("Help", open=False):
363
  gr.Markdown(help_text)
364
 
365
+
366
 
367
  add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
368
  outputs= [row2, row3, add_concept_button, sega_concepts_counter], queue = False)
369
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
371
  run_button.click(
372
  fn = randomize_seed_fn,
 
386
  tar_cfg_scale
387
  ],
388
  outputs=[wts, zs, do_inversion],
 
389
  ).success(
390
  fn=edit,
391
  inputs=[input_image,
 
407
  outputs = [reconstruct_button]
408
  )
409
 
410
+ reconstruct_button.click(
411
+ fn = show_reconstruction,
412
+ outputs = [ddpm_edited_image]
413
+ ).then(
414
+ fn = reconstruct,
415
+ inputs = [tar_prompt,
416
+ tar_cfg_scale,
417
+ skip,
418
+ wts, zs],
419
+ outputs = [ddpm_edited_image]
420
+ )
421
+
422
 
423
  # Automatically start inverting upon input_image change
424
  input_image.change(