Spaces:
Running
Running
Commit
•
4ac3513
1
Parent(s):
f229092
Poli changes
Browse files- Make the input component always display only one
- Show the hidden fields with examples
app.py
CHANGED
@@ -9,14 +9,15 @@ from constants import *
|
|
9 |
from inversion_utils import *
|
10 |
from modified_pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline
|
11 |
from torch import autocast, inference_mode
|
12 |
-
from diffusers import
|
13 |
from diffusers import DDIMScheduler
|
14 |
from transformers import AutoProcessor, BlipForConditionalGeneration
|
15 |
|
|
|
16 |
# load pipelines
|
17 |
-
sd_model_id = "stabilityai/stable-diffusion-2-base"
|
18 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
19 |
-
sd_pipe =
|
20 |
sd_pipe.scheduler = DDIMScheduler.from_config(sd_model_id, subfolder = "scheduler")
|
21 |
sem_pipe = SemanticStableDiffusionPipeline.from_pretrained(sd_model_id).to(device)
|
22 |
blip_processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
@@ -134,7 +135,6 @@ def edit(input_image,
|
|
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],
|
@@ -202,6 +202,7 @@ def get_example():
|
|
202 |
|
203 |
7,7,
|
204 |
1,2,
|
|
|
205 |
100,
|
206 |
36,
|
207 |
15,
|
@@ -254,6 +255,30 @@ def get_example():
|
|
254 |
]
|
255 |
return case
|
256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
|
259 |
########
|
@@ -310,28 +335,45 @@ help_text = """
|
|
310 |
|
311 |
with gr.Blocks(css="style.css") as demo:
|
312 |
|
313 |
-
def remove_concept():
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
guidance_scale_label = "Concept Guidance Scale"
|
315 |
enable_interactive = gr.update(interactive=True)
|
316 |
-
return
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
|
|
324 |
|
325 |
|
326 |
-
|
327 |
-
|
328 |
guidance_scale_label = "Concept Guidance Scale"
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
|
336 |
|
337 |
def display_editing_options(run_button, clear_button, sega_tab):
|
@@ -350,7 +392,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
350 |
|
351 |
|
352 |
def update_dropdown_parms(dropdown):
|
353 |
-
if dropdown == '
|
354 |
return DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD
|
355 |
elif dropdown =='style':
|
356 |
return STYLE_SEGA_CONCEPT_GUIDANCE_SCALE,STYLE_WARMUP_STEPS, STYLE_THRESHOLD
|
@@ -385,7 +427,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
385 |
reconstruction = gr.State()
|
386 |
do_inversion = gr.State(value=True)
|
387 |
do_reconstruction = gr.State(value=True)
|
388 |
-
sega_concepts_counter = gr.State(
|
389 |
|
390 |
|
391 |
|
@@ -400,29 +442,29 @@ with gr.Blocks(css="style.css") as demo:
|
|
400 |
with gr.Row():
|
401 |
with gr.Box(visible=False) as box1:
|
402 |
with gr.Row():
|
403 |
-
concept_1 = gr.Button(
|
404 |
-
remove_concept1 = gr.Button("x", scale=1)
|
405 |
with gr.Row():
|
406 |
guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
407 |
-
info="How strongly the concept should
|
408 |
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
409 |
-
step=0.5, interactive=True
|
410 |
with gr.Box(visible=False) as box2:
|
411 |
with gr.Row():
|
412 |
-
concept_2 = gr.Button(
|
413 |
-
remove_concept2 = gr.Button("x", scale=1)
|
414 |
with gr.Row():
|
415 |
guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
416 |
-
info="How strongly the concept should
|
417 |
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
418 |
-
step=0.5, interactive=True
|
419 |
with gr.Box(visible=False) as box3:
|
420 |
with gr.Row():
|
421 |
concept_3 = gr.Button(visible=False, scale=3)
|
422 |
-
remove_concept3 = gr.Button("x", scale=1)
|
423 |
with gr.Row():
|
424 |
guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
425 |
-
info="How strongly the concept should
|
426 |
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
427 |
step=0.5, interactive=True,visible=False)
|
428 |
|
@@ -433,34 +475,34 @@ with gr.Blocks(css="style.css") as demo:
|
|
433 |
|
434 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
435 |
tar_prompt = gr.Textbox(
|
436 |
-
label="
|
437 |
# show_label=False,
|
438 |
max_lines=1, value="",
|
439 |
-
placeholder="
|
440 |
)
|
441 |
|
442 |
with gr.Box():
|
443 |
-
intro_segs = gr.Markdown("Add/Remove
|
444 |
# 1st SEGA concept
|
445 |
-
with gr.Row().style(mobile_collapse=False):
|
446 |
with gr.Column(scale=3, min_width=100):
|
447 |
edit_concept_1 = gr.Textbox(
|
448 |
label="Edit Concept",
|
449 |
-
show_label=
|
450 |
max_lines=1, value="",
|
451 |
placeholder="E.g.: Sunglasses",
|
452 |
)
|
453 |
-
with gr.Column(scale=1, min_width=100):
|
454 |
-
neg_guidance_1 = gr.Checkbox(
|
455 |
-
label='Remove Concept?')
|
456 |
with gr.Column(scale=2, min_width=100):
|
457 |
-
dropdown1 = gr.Dropdown(label = "Edit Type", value ='
|
458 |
|
459 |
|
460 |
-
|
|
|
|
|
461 |
|
462 |
with gr.Column(scale=1, min_width=100):
|
463 |
-
add_1 = gr.Button('
|
|
|
464 |
|
465 |
|
466 |
# 2nd SEGA concept
|
@@ -468,41 +510,43 @@ with gr.Blocks(css="style.css") as demo:
|
|
468 |
with gr.Column(scale=3, min_width=100):
|
469 |
edit_concept_2 = gr.Textbox(
|
470 |
label="Edit Concept",
|
471 |
-
show_label=
|
472 |
max_lines=1,
|
473 |
placeholder="E.g.: Realistic",
|
474 |
)
|
475 |
-
with gr.Column(scale=1, min_width=100):
|
476 |
neg_guidance_2 = gr.Checkbox(
|
477 |
-
label='Remove Concept?'
|
478 |
with gr.Column(scale=2, min_width=100):
|
479 |
-
dropdown2 = gr.Dropdown(label = "Edit Type", value ='
|
480 |
|
481 |
with gr.Column(scale=1, min_width=100):
|
482 |
-
add_2 = gr.Button('
|
|
|
483 |
|
484 |
# 3rd SEGA concept
|
485 |
with gr.Row(visible=False).style(equal_height=True) as row3:
|
486 |
with gr.Column(scale=3, min_width=100):
|
487 |
edit_concept_3 = gr.Textbox(
|
488 |
label="Edit Concept",
|
489 |
-
show_label=
|
490 |
max_lines=1,
|
491 |
placeholder="E.g.: orange",
|
492 |
)
|
493 |
-
with gr.Column(scale=1, min_width=100):
|
494 |
neg_guidance_3 = gr.Checkbox(
|
495 |
label='Remove Concept?',visible=True)
|
496 |
with gr.Column(scale=2, min_width=100):
|
497 |
-
dropdown3 = gr.Dropdown(label = "Edit Type", value ='
|
498 |
with gr.Column(scale=1, min_width=100):
|
499 |
add_3 = gr.Button('Include')
|
|
|
500 |
|
|
|
|
|
501 |
|
502 |
-
|
503 |
-
|
504 |
-
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
505 |
-
add_concept_button = gr.Button("+1 concept")
|
506 |
|
507 |
|
508 |
with gr.Row():
|
@@ -530,28 +574,31 @@ with gr.Blocks(css="style.css") as demo:
|
|
530 |
|
531 |
with gr.TabItem('SEGA options', id=3) as sega_advanced_tab:
|
532 |
# 1st SEGA concept
|
|
|
533 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
534 |
warmup_1 = gr.Slider(label='Warmup', minimum=0, maximum=50,
|
535 |
value=DEFAULT_WARMUP_STEPS,
|
536 |
step=1, interactive=True)
|
537 |
threshold_1 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99,
|
538 |
-
value=DEFAULT_THRESHOLD,
|
539 |
|
540 |
# 2nd SEGA concept
|
541 |
-
|
|
|
542 |
warmup_2 = gr.Slider(label='Warmup', minimum=0, maximum=50,
|
543 |
value=DEFAULT_WARMUP_STEPS,
|
544 |
step=1, interactive=True)
|
545 |
threshold_2 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99,
|
546 |
value=DEFAULT_THRESHOLD,
|
547 |
-
|
548 |
# 3rd SEGA concept
|
549 |
-
|
|
|
550 |
warmup_3 = gr.Slider(label='Warmup', minimum=0, maximum=50,
|
551 |
value=DEFAULT_WARMUP_STEPS, step=1,
|
552 |
interactive=True)
|
553 |
threshold_3 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99,
|
554 |
-
value=DEFAULT_THRESHOLD,
|
555 |
interactive=True)
|
556 |
|
557 |
# caption_button.click(
|
@@ -559,19 +606,23 @@ with gr.Blocks(css="style.css") as demo:
|
|
559 |
# inputs = [input_image],
|
560 |
# outputs = [tar_prompt]
|
561 |
# )
|
562 |
-
neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
|
563 |
-
neg_guidance_2.change(fn = update_label, inputs=[neg_guidance_2], outputs=[add_2])
|
564 |
-
neg_guidance_3.change(fn = update_label, inputs=[neg_guidance_3], outputs=[add_3])
|
565 |
-
add_1.click(fn = update_display_concept, inputs=[add_1, edit_concept_1, neg_guidance_1], outputs=[box1, concept_1,
|
566 |
-
add_2.click(fn = update_display_concept, inputs=[add_2, edit_concept_2, neg_guidance_2], outputs=[box2, concept_2,
|
567 |
-
add_3.click(fn = update_display_concept, inputs=[add_3, edit_concept_3, neg_guidance_3], outputs=[box3, concept_3,
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
|
|
|
|
|
|
|
|
572 |
|
573 |
-
add_concept_button.click(fn =
|
574 |
-
|
575 |
|
576 |
run_button.click(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion], outputs=[inversion_progress],queue=False).then(
|
577 |
fn=load_and_invert,
|
@@ -608,7 +659,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
608 |
|
609 |
|
610 |
# Automatically start inverting upon input_image change
|
611 |
-
input_image.
|
612 |
fn = reset_do_inversion,
|
613 |
inputs = [input_image],
|
614 |
outputs = [do_inversion],
|
@@ -715,6 +766,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
715 |
|
716 |
gr.Examples(
|
717 |
label='Examples',
|
|
|
|
|
718 |
examples=get_example(),
|
719 |
inputs=[input_image,
|
720 |
# src_prompt,
|
@@ -731,17 +784,12 @@ with gr.Blocks(css="style.css") as demo:
|
|
731 |
steps,
|
732 |
skip,
|
733 |
tar_cfg_scale,
|
734 |
-
|
735 |
],
|
736 |
-
outputs=[
|
|
|
737 |
)
|
738 |
|
739 |
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
demo.queue()
|
744 |
-
demo.launch(share=
|
745 |
-
|
746 |
-
|
747 |
-
|
|
|
9 |
from inversion_utils import *
|
10 |
from modified_pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline
|
11 |
from torch import autocast, inference_mode
|
12 |
+
from diffusers import DiffusionPipeline
|
13 |
from diffusers import DDIMScheduler
|
14 |
from transformers import AutoProcessor, BlipForConditionalGeneration
|
15 |
|
16 |
+
torch.cuda.empty_cache()
|
17 |
# load pipelines
|
18 |
+
sd_model_id = "stabilityai/stable-diffusion-2-1-base"
|
19 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
20 |
+
sd_pipe = DiffusionPipeline.from_pretrained(sd_model_id).to(device)
|
21 |
sd_pipe.scheduler = DDIMScheduler.from_config(sd_model_id, subfolder = "scheduler")
|
22 |
sem_pipe = SemanticStableDiffusionPipeline.from_pretrained(sd_model_id).to(device)
|
23 |
blip_processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
|
135 |
do_reconstruction,
|
136 |
reconstruction):
|
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],
|
|
|
202 |
|
203 |
7,7,
|
204 |
1,2,
|
205 |
+
False,False,
|
206 |
100,
|
207 |
36,
|
208 |
15,
|
|
|
255 |
]
|
256 |
return case
|
257 |
|
258 |
+
def swap_visibilities(input_image,
|
259 |
+
tar_prompt,
|
260 |
+
edit_concept_1,
|
261 |
+
edit_concept_2,
|
262 |
+
sega_edited_image,
|
263 |
+
guidnace_scale_1,
|
264 |
+
guidnace_scale_2,
|
265 |
+
warmup_1,
|
266 |
+
warmup_2,
|
267 |
+
neg_guidance_1,
|
268 |
+
neg_guidance_2,
|
269 |
+
steps,
|
270 |
+
skip,
|
271 |
+
tar_cfg_scale,
|
272 |
+
sega_concepts_counter=0
|
273 |
+
|
274 |
+
):
|
275 |
+
concept1_update = update_display_concept("Remove" if neg_guidance_1 else "Add", edit_concept_1, neg_guidance_1, sega_concepts_counter)
|
276 |
+
if(edit_concept_2 != ""):
|
277 |
+
concept2_update = update_display_concept("Remove" if neg_guidance_2 else "Add", edit_concept_2, neg_guidance_2, sega_concepts_counter)
|
278 |
+
else:
|
279 |
+
concept2_update = gr.update(visible=False), gr.update(visible=False),gr.update(visible=False), gr.update(value=neg_guidance_2),gr.update(visible=True),gr.update(visible=False),sega_concepts_counter
|
280 |
+
return (*concept1_update,*concept2_update)
|
281 |
+
|
282 |
|
283 |
|
284 |
########
|
|
|
335 |
|
336 |
with gr.Blocks(css="style.css") as demo:
|
337 |
|
338 |
+
def remove_concept(sega_concepts_counter):
|
339 |
+
sega_concepts_counter -= 1
|
340 |
+
rows_visibility = [gr.update(visible=False) for _ in range(4)]
|
341 |
+
rows_visibility[sega_concepts_counter] = gr.update(visible=True)
|
342 |
+
|
343 |
+
row1_visibility, row2_visibility, row3_visibility, row4_visibility = rows_visibility
|
344 |
+
|
345 |
guidance_scale_label = "Concept Guidance Scale"
|
346 |
enable_interactive = gr.update(interactive=True)
|
347 |
+
return (gr.update(visible=False),
|
348 |
+
gr.update(visible=False, value="",),
|
349 |
+
gr.update(interactive=True, value=""),
|
350 |
+
gr.update(visible=False,label = guidance_scale_label),
|
351 |
+
gr.update(interactive=True, value =False),
|
352 |
+
gr.update(visible=True),
|
353 |
+
enable_interactive,
|
354 |
+
row1_visibility,
|
355 |
+
row2_visibility,
|
356 |
+
row3_visibility,
|
357 |
+
row4_visibility,
|
358 |
+
sega_concepts_counter
|
359 |
+
)
|
360 |
|
361 |
|
362 |
+
def update_display_concept(button_label, edit_concept, neg_guidance, sega_concepts_counter):
|
363 |
+
sega_concepts_counter+=1
|
364 |
guidance_scale_label = "Concept Guidance Scale"
|
365 |
+
if(button_label=='Remove'):
|
366 |
+
neg_guidance = True
|
367 |
+
guidance_scale_label = "Negative Guidance Scale"
|
368 |
+
|
369 |
+
return (gr.update(visible=True), #boxn
|
370 |
+
gr.update(visible=True, value=edit_concept), #concept_n
|
371 |
+
gr.update(visible=True,label = guidance_scale_label), #guidance_scale_n
|
372 |
+
gr.update(value=neg_guidance),#neg_guidance_n
|
373 |
+
gr.update(visible=False), #row_n
|
374 |
+
gr.update(visible=True), #row_n+1
|
375 |
+
sega_concepts_counter
|
376 |
+
)
|
377 |
|
378 |
|
379 |
def display_editing_options(run_button, clear_button, sega_tab):
|
|
|
392 |
|
393 |
|
394 |
def update_dropdown_parms(dropdown):
|
395 |
+
if dropdown == 'custom':
|
396 |
return DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,DEFAULT_WARMUP_STEPS, DEFAULT_THRESHOLD
|
397 |
elif dropdown =='style':
|
398 |
return STYLE_SEGA_CONCEPT_GUIDANCE_SCALE,STYLE_WARMUP_STEPS, STYLE_THRESHOLD
|
|
|
427 |
reconstruction = gr.State()
|
428 |
do_inversion = gr.State(value=True)
|
429 |
do_reconstruction = gr.State(value=True)
|
430 |
+
sega_concepts_counter = gr.State(0)
|
431 |
|
432 |
|
433 |
|
|
|
442 |
with gr.Row():
|
443 |
with gr.Box(visible=False) as box1:
|
444 |
with gr.Row():
|
445 |
+
concept_1 = gr.Button(scale=3)
|
446 |
+
remove_concept1 = gr.Button("x", scale=1, min_width=10)
|
447 |
with gr.Row():
|
448 |
guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
449 |
+
info="How strongly the concept should modify the image",
|
450 |
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
451 |
+
step=0.5, interactive=True)
|
452 |
with gr.Box(visible=False) as box2:
|
453 |
with gr.Row():
|
454 |
+
concept_2 = gr.Button(scale=3)
|
455 |
+
remove_concept2 = gr.Button("x", scale=1, min_width=10)
|
456 |
with gr.Row():
|
457 |
guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
458 |
+
info="How strongly the concept should modify the image",
|
459 |
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
460 |
+
step=0.5, interactive=True)
|
461 |
with gr.Box(visible=False) as box3:
|
462 |
with gr.Row():
|
463 |
concept_3 = gr.Button(visible=False, scale=3)
|
464 |
+
remove_concept3 = gr.Button("x", scale=1, min_width=10)
|
465 |
with gr.Row():
|
466 |
guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
467 |
+
info="How strongly the concept should modify the image",
|
468 |
value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
469 |
step=0.5, interactive=True,visible=False)
|
470 |
|
|
|
475 |
|
476 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
477 |
tar_prompt = gr.Textbox(
|
478 |
+
label="Describe your edited image",
|
479 |
# show_label=False,
|
480 |
max_lines=1, value="",
|
481 |
+
placeholder="Target prompt, DDPM Inversion",
|
482 |
)
|
483 |
|
484 |
with gr.Box():
|
485 |
+
intro_segs = gr.Markdown("Add/Remove SEGA Concepts from your Image")
|
486 |
# 1st SEGA concept
|
487 |
+
with gr.Row().style(mobile_collapse=False) as row1:
|
488 |
with gr.Column(scale=3, min_width=100):
|
489 |
edit_concept_1 = gr.Textbox(
|
490 |
label="Edit Concept",
|
491 |
+
show_label=True,
|
492 |
max_lines=1, value="",
|
493 |
placeholder="E.g.: Sunglasses",
|
494 |
)
|
|
|
|
|
|
|
495 |
with gr.Column(scale=2, min_width=100):
|
496 |
+
dropdown1 = gr.Dropdown(label = "Edit Type", value ='custom' , choices=['custom','style', 'object', 'facial'])
|
497 |
|
498 |
|
499 |
+
with gr.Column(scale=1, min_width=100, visible=False):
|
500 |
+
neg_guidance_1 = gr.Checkbox(
|
501 |
+
label='Remove Concept?')
|
502 |
|
503 |
with gr.Column(scale=1, min_width=100):
|
504 |
+
add_1 = gr.Button('Add')
|
505 |
+
remove_1 = gr.Button('Remove')
|
506 |
|
507 |
|
508 |
# 2nd SEGA concept
|
|
|
510 |
with gr.Column(scale=3, min_width=100):
|
511 |
edit_concept_2 = gr.Textbox(
|
512 |
label="Edit Concept",
|
513 |
+
show_label=True,
|
514 |
max_lines=1,
|
515 |
placeholder="E.g.: Realistic",
|
516 |
)
|
517 |
+
with gr.Column(scale=1, min_width=100, visible=False):
|
518 |
neg_guidance_2 = gr.Checkbox(
|
519 |
+
label='Remove Concept?')
|
520 |
with gr.Column(scale=2, min_width=100):
|
521 |
+
dropdown2 = gr.Dropdown(label = "Edit Type", value ='custom' , choices=['custom','style', 'object', 'facial'])
|
522 |
|
523 |
with gr.Column(scale=1, min_width=100):
|
524 |
+
add_2 = gr.Button('Add')
|
525 |
+
remove_2 = gr.Button('Remove')
|
526 |
|
527 |
# 3rd SEGA concept
|
528 |
with gr.Row(visible=False).style(equal_height=True) as row3:
|
529 |
with gr.Column(scale=3, min_width=100):
|
530 |
edit_concept_3 = gr.Textbox(
|
531 |
label="Edit Concept",
|
532 |
+
show_label=True,
|
533 |
max_lines=1,
|
534 |
placeholder="E.g.: orange",
|
535 |
)
|
536 |
+
with gr.Column(scale=1, min_width=100, visible=False):
|
537 |
neg_guidance_3 = gr.Checkbox(
|
538 |
label='Remove Concept?',visible=True)
|
539 |
with gr.Column(scale=2, min_width=100):
|
540 |
+
dropdown3 = gr.Dropdown(label = "Edit Type", value ='custom' , choices=['custom','style', 'object', 'facial'])
|
541 |
with gr.Column(scale=1, min_width=100):
|
542 |
add_3 = gr.Button('Include')
|
543 |
+
remove_3 = gr.Button('Remove')
|
544 |
|
545 |
+
with gr.Row(visible=False).style(equal_height=True) as row4:
|
546 |
+
gr.Markdown("### Max of 3 concepts reached. Remove a concept to add more")
|
547 |
|
548 |
+
#with gr.Row(visible=False).style(mobile_collapse=False, equal_height=True):
|
549 |
+
# add_concept_button = gr.Button("+1 concept")
|
|
|
|
|
550 |
|
551 |
|
552 |
with gr.Row():
|
|
|
574 |
|
575 |
with gr.TabItem('SEGA options', id=3) as sega_advanced_tab:
|
576 |
# 1st SEGA concept
|
577 |
+
gr.Markdown("1st concept")
|
578 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
579 |
warmup_1 = gr.Slider(label='Warmup', minimum=0, maximum=50,
|
580 |
value=DEFAULT_WARMUP_STEPS,
|
581 |
step=1, interactive=True)
|
582 |
threshold_1 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99,
|
583 |
+
value=DEFAULT_THRESHOLD, step=0.01, interactive=True)
|
584 |
|
585 |
# 2nd SEGA concept
|
586 |
+
gr.Markdown("2nd concept")
|
587 |
+
with gr.Row() as row2_advanced:
|
588 |
warmup_2 = gr.Slider(label='Warmup', minimum=0, maximum=50,
|
589 |
value=DEFAULT_WARMUP_STEPS,
|
590 |
step=1, interactive=True)
|
591 |
threshold_2 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99,
|
592 |
value=DEFAULT_THRESHOLD,
|
593 |
+
step=0.01, interactive=True)
|
594 |
# 3rd SEGA concept
|
595 |
+
gr.Markdown("3rd concept")
|
596 |
+
with gr.Row() as row3_advanced:
|
597 |
warmup_3 = gr.Slider(label='Warmup', minimum=0, maximum=50,
|
598 |
value=DEFAULT_WARMUP_STEPS, step=1,
|
599 |
interactive=True)
|
600 |
threshold_3 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99,
|
601 |
+
value=DEFAULT_THRESHOLD, step=0.01,
|
602 |
interactive=True)
|
603 |
|
604 |
# caption_button.click(
|
|
|
606 |
# inputs = [input_image],
|
607 |
# outputs = [tar_prompt]
|
608 |
# )
|
609 |
+
#neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
|
610 |
+
#neg_guidance_2.change(fn = update_label, inputs=[neg_guidance_2], outputs=[add_2])
|
611 |
+
#neg_guidance_3.change(fn = update_label, inputs=[neg_guidance_3], outputs=[add_3])
|
612 |
+
add_1.click(fn = update_display_concept, inputs=[add_1, edit_concept_1, neg_guidance_1, sega_concepts_counter], outputs=[box1, concept_1, guidnace_scale_1,neg_guidance_1,row1, row2, sega_concepts_counter],queue=False)
|
613 |
+
add_2.click(fn = update_display_concept, inputs=[add_2, edit_concept_2, neg_guidance_2, sega_concepts_counter], outputs=[box2, concept_2, guidnace_scale_2,neg_guidance_2,row2, row3, sega_concepts_counter],queue=False)
|
614 |
+
add_3.click(fn = update_display_concept, inputs=[add_3, edit_concept_3, neg_guidance_3, sega_concepts_counter], outputs=[box3, concept_3, guidnace_scale_3,neg_guidance_3,row3, row4, sega_concepts_counter],queue=False)
|
615 |
+
|
616 |
+
remove_1.click(fn = update_display_concept, inputs=[remove_1, edit_concept_1, neg_guidance_1, sega_concepts_counter], outputs=[box1, concept_1, guidnace_scale_1,neg_guidance_1,row1, row2, sega_concepts_counter],queue=False)
|
617 |
+
remove_2.click(fn = update_display_concept, inputs=[remove_2, edit_concept_2, neg_guidance_2 ,sega_concepts_counter], outputs=[box2, concept_2, guidnace_scale_2,neg_guidance_2,row2, row3,sega_concepts_counter],queue=False)
|
618 |
+
remove_3.click(fn = update_display_concept, inputs=[remove_3, edit_concept_3, neg_guidance_3, sega_concepts_counter], outputs=[box3, concept_3, guidnace_scale_3,neg_guidance_3, row3, row4, sega_concepts_counter],queue=False)
|
619 |
+
|
620 |
+
remove_concept1.click(fn = remove_concept, inputs=sega_concepts_counter, outputs= [box1, concept_1, edit_concept_1, guidnace_scale_1,neg_guidance_1, add_1, dropdown1, row1, row2, row3, row4, sega_concepts_counter],queue=False)
|
621 |
+
remove_concept2.click(fn = remove_concept, inputs=sega_concepts_counter, outputs=[box2, concept_2, edit_concept_2, guidnace_scale_2,neg_guidance_2, add_2 , dropdown2, row1, row2, row3, row4, sega_concepts_counter],queue=False)
|
622 |
+
remove_concept3.click(fn = remove_concept, inputs=sega_concepts_counter, outputs=[box3, concept_3, edit_concept_3, guidnace_scale_3,neg_guidance_3, add_3, dropdown3, row1, row2, row3, row4, sega_concepts_counter],queue=False)
|
623 |
|
624 |
+
#add_concept_button.click(fn = update_display_concept, inputs=sega_concepts_counter,
|
625 |
+
# outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)
|
626 |
|
627 |
run_button.click(fn = update_inversion_progress_visibility, inputs =[input_image,do_inversion], outputs=[inversion_progress],queue=False).then(
|
628 |
fn=load_and_invert,
|
|
|
659 |
|
660 |
|
661 |
# Automatically start inverting upon input_image change
|
662 |
+
input_image.upload(
|
663 |
fn = reset_do_inversion,
|
664 |
inputs = [input_image],
|
665 |
outputs = [do_inversion],
|
|
|
766 |
|
767 |
gr.Examples(
|
768 |
label='Examples',
|
769 |
+
fn=swap_visibilities,
|
770 |
+
run_on_click=True,
|
771 |
examples=get_example(),
|
772 |
inputs=[input_image,
|
773 |
# src_prompt,
|
|
|
784 |
steps,
|
785 |
skip,
|
786 |
tar_cfg_scale,
|
787 |
+
sega_concepts_counter
|
788 |
],
|
789 |
+
outputs=[box1, concept_1, guidnace_scale_1,neg_guidance_1, row1, row2, sega_concepts_counter,box2, concept_2, guidnace_scale_2,neg_guidance_2,row2, row3,sega_concepts_counter],
|
790 |
+
cache_examples=True
|
791 |
)
|
792 |
|
793 |
|
|
|
|
|
|
|
794 |
demo.queue()
|
795 |
+
demo.launch(share=True)
|
|
|
|
|
|