Spaces:
Running
Running
Linoy Tsaban
commited on
Commit
•
8c532f2
1
Parent(s):
a44c2bb
Update app.py
Browse filesupdated (still intermediate) sega concept adding ui
app.py
CHANGED
@@ -267,11 +267,32 @@ help_text = """
|
|
267 |
|
268 |
with gr.Blocks(css='style.css') as demo:
|
269 |
|
|
|
270 |
def add_concept(sega_concepts_counter):
|
271 |
if sega_concepts_counter == 1:
|
272 |
-
return row2.update(visible=True), row3.update(visible=False), add_concept_button.update(visible=True), 2
|
273 |
else:
|
274 |
-
return row2.update(visible=True), row3.update(visible=True), add_concept_button.update(visible=False), 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
|
277 |
def reset_do_inversion():
|
@@ -282,18 +303,13 @@ with gr.Blocks(css='style.css') as demo:
|
|
282 |
do_reconstruction = True
|
283 |
return do_reconstruction
|
284 |
|
285 |
-
|
286 |
-
|
287 |
-
if do_inversion:
|
288 |
return inversion_progress.update(visible=True)
|
289 |
else:
|
290 |
return inversion_progress.update(visible=False)
|
291 |
|
292 |
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
gr.HTML(intro)
|
298 |
wts = gr.State()
|
299 |
zs = gr.State()
|
@@ -303,7 +319,6 @@ with gr.Blocks(css='style.css') as demo:
|
|
303 |
sega_concepts_counter = gr.State(1)
|
304 |
|
305 |
|
306 |
-
|
307 |
with gr.Row():
|
308 |
input_image = gr.Image(label="Input Image", interactive=True)
|
309 |
ddpm_edited_image = gr.Image(label=f"DDPM Reconstructed Image", interactive=False, visible=False)
|
@@ -312,6 +327,32 @@ with gr.Blocks(css='style.css') as demo:
|
|
312 |
ddpm_edited_image.style(height=365, width=365)
|
313 |
sega_edited_image.style(height=365, width=365)
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
with gr.Row():
|
316 |
inversion_progress = gr.Textbox(visible=False, label="Inversion progress")
|
317 |
|
@@ -322,54 +363,60 @@ with gr.Blocks(css='style.css') as demo:
|
|
322 |
label="Edit Concept",
|
323 |
show_label=False,
|
324 |
max_lines=1,
|
325 |
-
placeholder="Enter your 1st edit prompt",
|
326 |
)
|
327 |
caption_button = gr.Button("Caption Image")
|
328 |
with gr.TabItem('2. Add SEGA edit concepts', id=1):
|
329 |
# 1st SEGA concept
|
330 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
331 |
-
neg_guidance_1 = gr.Checkbox(
|
332 |
-
label='Negative Guidance')
|
333 |
-
|
334 |
-
guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
335 |
-
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
336 |
-
step=0.5, interactive=True)
|
337 |
-
|
338 |
edit_concept_1 = gr.Textbox(
|
339 |
label="Edit Concept",
|
340 |
show_label=False,
|
341 |
max_lines=1,
|
342 |
placeholder="Enter your 1st edit prompt",
|
343 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
|
345 |
# 2nd SEGA concept
|
346 |
with gr.Row(visible=False) as row2:
|
347 |
-
neg_guidance_2 = gr.Checkbox(
|
348 |
-
label='Negative Guidance',visible=True)
|
349 |
-
guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
350 |
-
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
351 |
-
step=0.5, interactive=True)
|
352 |
edit_concept_2 = gr.Textbox(
|
353 |
label="Edit Concept",
|
354 |
show_label=False,
|
355 |
max_lines=1,
|
356 |
placeholder="Enter your 2st edit prompt",
|
357 |
)
|
358 |
-
|
359 |
-
with gr.Row(visible=False) as row3:
|
360 |
-
neg_guidance_3 = gr.Checkbox(
|
361 |
label='Negative Guidance',visible=True)
|
|
|
|
|
|
|
|
|
362 |
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
edit_concept_3 = gr.Textbox(
|
368 |
label="Edit Concept",
|
369 |
show_label=False,
|
370 |
max_lines=1,
|
371 |
placeholder="Enter your 3rd edit prompt",
|
372 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
375 |
add_concept_button = gr.Button("+")
|
@@ -382,6 +429,7 @@ with gr.Blocks(css='style.css') as demo:
|
|
382 |
|
383 |
with gr.Accordion("Advanced Options", open=False):
|
384 |
with gr.Tabs() as tabs:
|
|
|
385 |
with gr.TabItem('General options', id=2):
|
386 |
with gr.Row():
|
387 |
with gr.Column():
|
@@ -390,9 +438,11 @@ with gr.Blocks(css='style.css') as demo:
|
|
390 |
src_cfg_scale = gr.Number(value=3.5, label=f"Source Guidance Scale", interactive=True)
|
391 |
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
392 |
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
|
|
393 |
with gr.Column():
|
394 |
skip = gr.Slider(minimum=0, maximum=60, value=36, label="Skip Steps", interactive=True)
|
395 |
tar_cfg_scale = gr.Slider(minimum=7, maximum=30,value=15, label=f"Guidance Scale", interactive=True)
|
|
|
396 |
with gr.TabItem('SEGA options', id=3):
|
397 |
# 1st SEGA concept
|
398 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
@@ -419,23 +469,21 @@ with gr.Blocks(css='style.css') as demo:
|
|
419 |
value=DEFAULT_THRESHOLD, steps=0.01,
|
420 |
interactive=True)
|
421 |
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
# with gr.Accordion("Help", open=False):
|
427 |
-
# gr.Markdown(help_text)
|
428 |
-
|
429 |
caption_button.click(
|
430 |
fn = caption_image,
|
431 |
inputs = [input_image],
|
432 |
outputs = [tar_prompt]
|
433 |
)
|
434 |
|
|
|
|
|
|
|
|
|
|
|
435 |
add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
|
436 |
-
outputs= [row2, row3, add_concept_button, sega_concepts_counter], queue = False)
|
437 |
|
438 |
-
run_button.click(fn = update_inversion_progress_visibility, inputs =[do_inversion], outputs=[inversion_progress],queue=False).then(
|
439 |
fn=load_and_invert,
|
440 |
inputs=[input_image,
|
441 |
do_inversion,
|
@@ -449,7 +497,7 @@ with gr.Blocks(css='style.css') as demo:
|
|
449 |
tar_cfg_scale
|
450 |
],
|
451 |
outputs=[wts, zs, do_inversion, inversion_progress],
|
452 |
-
).then(fn = update_inversion_progress_visibility, inputs =[do_inversion], outputs=[inversion_progress],queue=False).success(
|
453 |
fn=edit,
|
454 |
inputs=[input_image,
|
455 |
wts, zs,
|
@@ -472,7 +520,7 @@ with gr.Blocks(css='style.css') as demo:
|
|
472 |
input_image.change(
|
473 |
fn = reset_do_inversion,
|
474 |
outputs = [do_inversion],
|
475 |
-
queue = False).then(fn = update_inversion_progress_visibility, inputs =[do_inversion],
|
476 |
outputs=[inversion_progress],queue=False).then(
|
477 |
fn=load_and_invert,
|
478 |
inputs=[input_image,
|
@@ -488,7 +536,7 @@ with gr.Blocks(css='style.css') as demo:
|
|
488 |
],
|
489 |
# outputs=[ddpm_edited_image, wts, zs, do_inversion],
|
490 |
outputs=[wts, zs, do_inversion, inversion_progress],
|
491 |
-
).then(fn = update_inversion_progress_visibility, inputs =[do_inversion],
|
492 |
outputs=[inversion_progress],queue=False).then(
|
493 |
lambda: reconstruct_button.update(visible=False),
|
494 |
outputs=[reconstruct_button]).then(
|
|
|
267 |
|
268 |
with gr.Blocks(css='style.css') as demo:
|
269 |
|
270 |
+
|
271 |
def add_concept(sega_concepts_counter):
|
272 |
if sega_concepts_counter == 1:
|
273 |
+
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
|
274 |
else:
|
275 |
+
return row2.update(visible=True), row2_advanced.update(visible=True), row3.update(visible=True), row3_advanced.update(visible=False), add_concept_button.update(visible=False), 3
|
276 |
+
|
277 |
+
def update_display_concept_1(add_1, edit_concept_1):
|
278 |
+
if add_1 == 'Add':
|
279 |
+
return edit_concept_1, concept_1.update(visible=True), edit_concept_1, guidnace_scale_1.update(visible=True), "Clear"
|
280 |
+
else: # remove
|
281 |
+
return "", concept_1.update(visible=False), "", guidnace_scale_1.update(visible=False), "Add"
|
282 |
+
|
283 |
+
def update_display_concept_2(add_2, edit_concept_2):
|
284 |
+
if add_2 == 'Add':
|
285 |
+
return edit_concept_2, concept_2.update(visible=True),edit_concept_2, guidnace_scale_2.update(visible=True), "Clear"
|
286 |
+
else: # remove
|
287 |
+
return "", concept_2.update(visible=False), "", guidnace_scale_2.update(visible=False), "Add"
|
288 |
+
|
289 |
+
def update_display_concept_3(add_3, edit_concept_3):
|
290 |
+
if add_3 == 'Add':
|
291 |
+
return edit_concept_3, concept_3.update(visible=True), edit_concept_3, guidnace_scale_3.update(visible=True), "Clear"
|
292 |
+
else: # remove
|
293 |
+
return "", concept_3.update(visible=False), "", guidnace_scale_3.update(visible=False), "Add"
|
294 |
+
|
295 |
+
|
296 |
|
297 |
|
298 |
def reset_do_inversion():
|
|
|
303 |
do_reconstruction = True
|
304 |
return do_reconstruction
|
305 |
|
306 |
+
def update_inversion_progress_visibility(input_image, do_inversion):
|
307 |
+
if do_inversion and not input_image is None:
|
|
|
308 |
return inversion_progress.update(visible=True)
|
309 |
else:
|
310 |
return inversion_progress.update(visible=False)
|
311 |
|
312 |
|
|
|
|
|
|
|
|
|
313 |
gr.HTML(intro)
|
314 |
wts = gr.State()
|
315 |
zs = gr.State()
|
|
|
319 |
sega_concepts_counter = gr.State(1)
|
320 |
|
321 |
|
|
|
322 |
with gr.Row():
|
323 |
input_image = gr.Image(label="Input Image", interactive=True)
|
324 |
ddpm_edited_image = gr.Image(label=f"DDPM Reconstructed Image", interactive=False, visible=False)
|
|
|
327 |
ddpm_edited_image.style(height=365, width=365)
|
328 |
sega_edited_image.style(height=365, width=365)
|
329 |
|
330 |
+
with gr.Row():
|
331 |
+
with gr.Column() as col1:
|
332 |
+
concept_1 = gr.Button(visible=False)
|
333 |
+
guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
334 |
+
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
335 |
+
step=0.5, interactive=True,visible=False)
|
336 |
+
with gr.Column() as col2:
|
337 |
+
concept_2 = gr.Button(visible=False)
|
338 |
+
guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
339 |
+
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
340 |
+
step=0.5, interactive=True,visible=False)
|
341 |
+
with gr.Column() as col3:
|
342 |
+
concept_3 = gr.Button(visible=False)
|
343 |
+
guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
344 |
+
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
345 |
+
step=0.5, interactive=True,visible=False)
|
346 |
+
|
347 |
+
|
348 |
+
|
349 |
+
with gr.Row():
|
350 |
+
gallery = gr.Gallery(visible = False).style(
|
351 |
+
columns=3,
|
352 |
+
object_fit='contain')
|
353 |
+
|
354 |
+
|
355 |
+
|
356 |
with gr.Row():
|
357 |
inversion_progress = gr.Textbox(visible=False, label="Inversion progress")
|
358 |
|
|
|
363 |
label="Edit Concept",
|
364 |
show_label=False,
|
365 |
max_lines=1,
|
366 |
+
placeholder="Enter your 1st edit prompt", elem_classes="feedback"
|
367 |
)
|
368 |
caption_button = gr.Button("Caption Image")
|
369 |
with gr.TabItem('2. Add SEGA edit concepts', id=1):
|
370 |
# 1st SEGA concept
|
371 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
edit_concept_1 = gr.Textbox(
|
373 |
label="Edit Concept",
|
374 |
show_label=False,
|
375 |
max_lines=1,
|
376 |
placeholder="Enter your 1st edit prompt",
|
377 |
)
|
378 |
+
neg_guidance_1 = gr.Checkbox(
|
379 |
+
label='Negative Guidance')
|
380 |
+
|
381 |
+
# guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
382 |
+
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
383 |
+
# step=0.5, interactive=True)
|
384 |
+
|
385 |
+
|
386 |
+
add_1 = gr.Button('Add')
|
387 |
|
388 |
# 2nd SEGA concept
|
389 |
with gr.Row(visible=False) as row2:
|
|
|
|
|
|
|
|
|
|
|
390 |
edit_concept_2 = gr.Textbox(
|
391 |
label="Edit Concept",
|
392 |
show_label=False,
|
393 |
max_lines=1,
|
394 |
placeholder="Enter your 2st edit prompt",
|
395 |
)
|
396 |
+
neg_guidance_2 = gr.Checkbox(
|
|
|
|
|
397 |
label='Negative Guidance',visible=True)
|
398 |
+
# guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
399 |
+
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
400 |
+
# step=0.5, interactive=True)
|
401 |
+
add_2 = gr.Button('Add')
|
402 |
|
403 |
+
# 3rd SEGA concept
|
404 |
+
with gr.Row(visible=False) as row3:
|
405 |
+
edit_concept_3 = gr.Textbox(
|
|
|
|
|
406 |
label="Edit Concept",
|
407 |
show_label=False,
|
408 |
max_lines=1,
|
409 |
placeholder="Enter your 3rd edit prompt",
|
410 |
)
|
411 |
+
neg_guidance_3 = gr.Checkbox(
|
412 |
+
label='Negative Guidance',visible=True)
|
413 |
+
# guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
414 |
+
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
415 |
+
# step=0.5, interactive=True)
|
416 |
+
add_3 = gr.Button('Add')
|
417 |
+
|
418 |
+
|
419 |
+
|
420 |
|
421 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
422 |
add_concept_button = gr.Button("+")
|
|
|
429 |
|
430 |
with gr.Accordion("Advanced Options", open=False):
|
431 |
with gr.Tabs() as tabs:
|
432 |
+
|
433 |
with gr.TabItem('General options', id=2):
|
434 |
with gr.Row():
|
435 |
with gr.Column():
|
|
|
438 |
src_cfg_scale = gr.Number(value=3.5, label=f"Source Guidance Scale", interactive=True)
|
439 |
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
440 |
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
441 |
+
|
442 |
with gr.Column():
|
443 |
skip = gr.Slider(minimum=0, maximum=60, value=36, label="Skip Steps", interactive=True)
|
444 |
tar_cfg_scale = gr.Slider(minimum=7, maximum=30,value=15, label=f"Guidance Scale", interactive=True)
|
445 |
+
|
446 |
with gr.TabItem('SEGA options', id=3):
|
447 |
# 1st SEGA concept
|
448 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
|
|
469 |
value=DEFAULT_THRESHOLD, steps=0.01,
|
470 |
interactive=True)
|
471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
caption_button.click(
|
473 |
fn = caption_image,
|
474 |
inputs = [input_image],
|
475 |
outputs = [tar_prompt]
|
476 |
)
|
477 |
|
478 |
+
add_1.click(fn = update_display_concept_1, inputs=[add_1, edit_concept_1], outputs=[concept_1, concept_1, edit_concept_1, guidnace_scale_1, add_1])
|
479 |
+
add_2.click(fn = update_display_concept_2, inputs=[add_2, edit_concept_2], outputs=[concept_2, concept_2, edit_concept_2, guidnace_scale_2, add_2])
|
480 |
+
add_3.click(fn = update_display_concept_3, inputs=[add_3, edit_concept_3], outputs=[concept_3, concept_3, edit_concept_3, guidnace_scale_3, add_3])
|
481 |
+
|
482 |
+
|
483 |
add_concept_button.click(fn = add_concept, inputs=sega_concepts_counter,
|
484 |
+
outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)
|
485 |
|
486 |
+
run_button.click(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion], outputs=[inversion_progress],queue=False).then(
|
487 |
fn=load_and_invert,
|
488 |
inputs=[input_image,
|
489 |
do_inversion,
|
|
|
497 |
tar_cfg_scale
|
498 |
],
|
499 |
outputs=[wts, zs, do_inversion, inversion_progress],
|
500 |
+
).then(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion], outputs=[inversion_progress],queue=False).success(
|
501 |
fn=edit,
|
502 |
inputs=[input_image,
|
503 |
wts, zs,
|
|
|
520 |
input_image.change(
|
521 |
fn = reset_do_inversion,
|
522 |
outputs = [do_inversion],
|
523 |
+
queue = False).then(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion],
|
524 |
outputs=[inversion_progress],queue=False).then(
|
525 |
fn=load_and_invert,
|
526 |
inputs=[input_image,
|
|
|
536 |
],
|
537 |
# outputs=[ddpm_edited_image, wts, zs, do_inversion],
|
538 |
outputs=[wts, zs, do_inversion, inversion_progress],
|
539 |
+
).then(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion],
|
540 |
outputs=[inversion_progress],queue=False).then(
|
541 |
lambda: reconstruct_button.update(visible=False),
|
542 |
outputs=[reconstruct_button]).then(
|