Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -461,154 +461,109 @@ pipe4.fuse_lora()
|
|
461 |
# pipe3.scheduler.set_timesteps(50)
|
462 |
######### Gradio Fuction #############
|
463 |
|
464 |
-
def swap_to_gallery(images):
|
465 |
-
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
466 |
-
|
467 |
-
def upload_example_to_gallery(images, prompt, style, negative_prompt):
|
468 |
-
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
469 |
-
|
470 |
-
def remove_back_to_files():
|
471 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
472 |
-
|
473 |
def remove_tips():
|
474 |
return gr.update(visible=False)
|
475 |
|
476 |
def apply_style_positive(style_name: str, positive: str):
|
477 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
478 |
-
return p.replace("{prompt}", positive)
|
479 |
|
480 |
def apply_style(style_name: str, positives: list, negative: str = ""):
|
481 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
482 |
return [p.replace("{prompt}", positive) for positive in positives], n + ' ' + negative
|
483 |
|
484 |
-
def
|
485 |
-
|
486 |
-
|
487 |
-
elif _model_type == "Using Ref Images":
|
488 |
-
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)
|
489 |
-
else:
|
490 |
-
raise ValueError("Invalid model type",_model_type)
|
491 |
|
492 |
|
493 |
######### Image Generation ##############
|
494 |
@spaces.GPU(duration=120)
|
495 |
-
def process_generation(_sd_type,
|
496 |
-
|
497 |
-
if _model_type == "Photomaker" and "img" not in general_prompt:
|
498 |
-
raise gr.Error("Please add the triger word \" img \" behind the class word you want to customize, such as: man img or woman img")
|
499 |
-
if _upload_images is None and _model_type != "original":
|
500 |
-
raise gr.Error(f"Cannot find any input face image!")
|
501 |
-
if len(prompt_array.splitlines()) > 10:
|
502 |
-
raise gr.Error(f"No more than 10 prompts in huggface demo for Speed! But found {len(prompt_array.splitlines())} prompts!")
|
503 |
-
global sa32, sa64,id_length,total_length,attn_procs,unet,cur_model_type,device
|
504 |
global num_steps
|
505 |
global write
|
506 |
-
global cur_step,attn_count
|
507 |
-
global height,width
|
508 |
height = G_height
|
509 |
width = G_width
|
510 |
-
global pipe2,pipe4
|
511 |
-
global sd_model_path,models_dict
|
|
|
512 |
sd_model_path = models_dict[_sd_type]
|
513 |
-
num_steps =_num_steps
|
514 |
use_safe_tensor = True
|
515 |
-
|
|
|
516 |
sd_model_path = models_dict["SDXL"]
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
pipe.enable_freeu(s1=0.6, s2=0.4, b1=1.1, b2=1.2)
|
521 |
-
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
522 |
-
# pipe.scheduler.set_timesteps(50)
|
523 |
-
set_attention_processor(pipe.unet,id_length_,is_ipadapter = False)
|
524 |
-
elif _model_type == "Photomaker":
|
525 |
-
if _sd_type != "SDXL" and style_name != "(No style)":
|
526 |
-
pipe = pipe2.to(device)
|
527 |
-
pipe.id_encoder.to(device)
|
528 |
-
set_attention_processor(pipe.unet,id_length_,is_ipadapter = False)
|
529 |
-
else:
|
530 |
-
pipe = pipe4.to(device)
|
531 |
-
pipe.id_encoder.to(device)
|
532 |
-
set_attention_processor(pipe.unet,id_length_,is_ipadapter = False)
|
533 |
-
else:
|
534 |
-
raise NotImplementedError("You should choice between original and Photomaker!",f"But you choice {_model_type}")
|
535 |
-
##### ########################
|
536 |
-
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
537 |
pipe.enable_freeu(s1=0.6, s2=0.4, b1=1.1, b2=1.2)
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
prompts = prompt_array.splitlines()
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
print(f"start_merge_step:{start_merge_step}")
|
549 |
generator = torch.Generator(device="cuda").manual_seed(seed_)
|
550 |
-
sa32, sa64 =
|
551 |
id_length = id_length_
|
552 |
clipped_prompts = prompts[:]
|
553 |
-
|
|
|
554 |
prompts = [prompt.rpartition('#')[0] if "#" in prompt else prompt for prompt in prompts]
|
555 |
-
|
556 |
id_prompts = prompts[:id_length]
|
557 |
real_prompts = prompts[id_length:]
|
|
|
558 |
torch.cuda.empty_cache()
|
559 |
write = True
|
560 |
cur_step = 0
|
561 |
-
|
562 |
attn_count = 0
|
|
|
563 |
id_prompts, negative_prompt = apply_style(style_name, id_prompts, negative_prompt)
|
|
|
564 |
setup_seed(seed_)
|
|
|
565 |
total_results = []
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
else:
|
571 |
-
raise NotImplementedError("You should choice between original and Photomaker!",f"But you choice {_model_type}")
|
572 |
total_results = id_images + total_results
|
573 |
yield total_results
|
|
|
|
|
574 |
real_images = []
|
575 |
write = False
|
576 |
for real_prompt in real_prompts:
|
577 |
setup_seed(seed_)
|
578 |
cur_step = 0
|
579 |
real_prompt = apply_style_positive(style_name, real_prompt)
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
real_images.append(pipe(real_prompt, input_id_images=input_id_images, num_inference_steps=_num_steps, guidance_scale=guidance_scale, start_merge_step = start_merge_step, height = height, width = width,negative_prompt = negative_prompt,generator = generator).images[0])
|
584 |
-
else:
|
585 |
-
raise NotImplementedError("You should choice between original and Photomaker!",f"But you choice {_model_type}")
|
586 |
total_results = [real_images[-1]] + total_results
|
587 |
yield total_results
|
|
|
|
|
588 |
if _comic_type != "No typesetting (default)":
|
589 |
-
captions= prompt_array.splitlines()
|
590 |
-
captions = [caption.replace("[NC]","") for caption in captions]
|
591 |
captions = [caption.split('#')[-1] if "#" in caption else caption for caption in captions]
|
592 |
from PIL import ImageFont
|
593 |
-
total_results = get_comic(id_images + real_images, _comic_type,captions=
|
594 |
-
|
595 |
-
pipe = pipe2.to("cpu")
|
596 |
-
pipe.id_encoder.to("cpu")
|
597 |
-
set_attention_processor(pipe.unet,id_length_,is_ipadapter = False)
|
598 |
-
yield total_results
|
599 |
-
|
600 |
|
|
|
601 |
|
602 |
def array2string(arr):
|
603 |
-
|
604 |
-
for i,part in enumerate(arr):
|
605 |
-
if i != len(arr)-1:
|
606 |
-
stringtmp += part +"\n"
|
607 |
-
else:
|
608 |
-
stringtmp += part
|
609 |
-
|
610 |
-
return stringtmp
|
611 |
-
|
612 |
|
613 |
#################################################
|
614 |
#################################################
|
@@ -617,167 +572,62 @@ with gr.Blocks(css=css) as demo:
|
|
617 |
binary_matrixes = gr.State([])
|
618 |
color_layout = gr.State([])
|
619 |
|
620 |
-
# gr.Markdown(logo)
|
621 |
gr.Markdown(title)
|
622 |
gr.Markdown(description)
|
623 |
|
624 |
with gr.Row():
|
625 |
with gr.Group(elem_id="main-image"):
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
# with gr.Column(visible=False) as post_sketch:
|
631 |
-
# for n in range(MAX_COLORS):
|
632 |
-
# if n == 0 :
|
633 |
-
# with gr.Row(visible=False) as color_row[n]:
|
634 |
-
# colors.append(gr.Image(shape=(100, 100), label="background", type="pil", image_mode="RGB", width=100, height=100))
|
635 |
-
# prompts.append(gr.Textbox(label="Prompt for the background (white region)", value=""))
|
636 |
-
# else:
|
637 |
-
# with gr.Row(visible=False) as color_row[n]:
|
638 |
-
# colors.append(gr.Image(shape=(100, 100), label="segment "+str(n), type="pil", image_mode="RGB", width=100, height=100))
|
639 |
-
# prompts.append(gr.Textbox(label="Prompt for the segment "+str(n)))
|
640 |
-
|
641 |
-
# get_genprompt_run = gr.Button("(2) I've finished segment labeling ! 😺", elem_id="prompt_button", interactive=True)
|
642 |
-
|
643 |
-
with gr.Column(visible=True) as gen_prompt_vis:
|
644 |
-
sd_type = gr.Dropdown(choices=list(models_dict.keys()), value = "SDXL",label="sd_type", info="Select pretrained model")
|
645 |
-
model_type = gr.Radio(["Only Using Textual Description", "Using Ref Images"], label="model_type", value = "Only Using Textual Description", info="Control type of the Character")
|
646 |
-
with gr.Group(visible=False) as control_image_input:
|
647 |
-
files = gr.Files(
|
648 |
-
label="Drag (Select) 1 or more photos of your face",
|
649 |
-
file_types=["image"],
|
650 |
-
)
|
651 |
-
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=5, rows=1, height=200)
|
652 |
-
with gr.Column(visible=False) as clear_button:
|
653 |
-
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
654 |
general_prompt = gr.Textbox(value='', label="(1) Textual Description for Character", interactive=True)
|
655 |
-
negative_prompt = gr.Textbox(value='', label="(2)
|
656 |
-
style = gr.Dropdown(label="Style
|
657 |
-
prompt_array = gr.Textbox(lines
|
658 |
-
|
659 |
-
|
660 |
-
sa32_ = gr.Slider(label="
|
661 |
-
sa64_ = gr.Slider(label="
|
662 |
-
id_length_ = gr.Slider(label=
|
663 |
-
# total_length_ = gr.Slider(label= "Number of total images", minimum=1, maximum=20, value=1, step=1)
|
664 |
seed_ = gr.Slider(label="Seed", minimum=-1, maximum=MAX_SEED, value=0, step=1)
|
665 |
-
num_steps = gr.Slider(
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
value=50,
|
671 |
-
)
|
672 |
-
G_height = gr.Slider(
|
673 |
-
label="height",
|
674 |
-
minimum=256,
|
675 |
-
maximum=1024,
|
676 |
-
step=32,
|
677 |
-
value=1024,
|
678 |
-
)
|
679 |
-
G_width = gr.Slider(
|
680 |
-
label="width",
|
681 |
-
minimum=256,
|
682 |
-
maximum=1024,
|
683 |
-
step=32,
|
684 |
-
value=1024,
|
685 |
-
)
|
686 |
-
comic_type = gr.Radio(["No typesetting (default)", "Four Pannel", "Classic Comic Style"], value = "Classic Comic Style", label="Typesetting Style", info="Select the typesetting style ")
|
687 |
-
guidance_scale = gr.Slider(
|
688 |
-
label="Guidance scale",
|
689 |
-
minimum=0.1,
|
690 |
-
maximum=10.0,
|
691 |
-
step=0.1,
|
692 |
-
value=5,
|
693 |
-
)
|
694 |
-
style_strength_ratio = gr.Slider(
|
695 |
-
label="Style strength of Ref Image (%)",
|
696 |
-
minimum=15,
|
697 |
-
maximum=50,
|
698 |
-
step=1,
|
699 |
-
value=20,
|
700 |
-
visible=False
|
701 |
-
)
|
702 |
-
Ip_Adapter_Strength = gr.Slider(
|
703 |
-
label="Ip_Adapter_Strength",
|
704 |
-
minimum=0,
|
705 |
-
maximum=1,
|
706 |
-
step=0.1,
|
707 |
-
value=0.5,
|
708 |
-
visible=False
|
709 |
-
)
|
710 |
-
final_run_btn = gr.Button("Generate ! 😺")
|
711 |
|
|
|
712 |
|
713 |
with gr.Column():
|
714 |
out_image = gr.Gallery(label="Result", columns=2, height='auto')
|
715 |
-
generated_information = gr.Markdown(label="Generation Details", value="",visible=False)
|
716 |
gr.Markdown(version)
|
717 |
-
model_type.change(fn = change_visiale_by_model_type , inputs = model_type, outputs=[control_image_input,style_strength_ratio,Ip_Adapter_Strength])
|
718 |
-
files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
|
719 |
-
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
|
720 |
-
|
721 |
-
final_run_btn.click(fn=set_text_unfinished, outputs = generated_information
|
722 |
-
).then(process_generation, inputs=[sd_type,model_type,files, num_steps,style, Ip_Adapter_Strength,style_strength_ratio, guidance_scale, seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt, prompt_array,G_height,G_width,comic_type], outputs=out_image
|
723 |
-
).then(fn=set_text_finished,outputs = generated_information)
|
724 |
|
|
|
|
|
|
|
|
|
|
|
|
|
725 |
|
726 |
gr.Examples(
|
727 |
examples=[
|
728 |
-
[0,0.5,0.5,2,"a scientist, wearing a lab coat and glasses",
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
array2string(["[NC]In a dark room filled with monitors #She types rapidly on a neon-lit keyboard",
|
741 |
-
"neon city street at night, people walking by",
|
742 |
-
"a robot chases her through a back alley",
|
743 |
-
"[NC]She jumps onto a rooftop, escaping",
|
744 |
-
]),
|
745 |
-
"Japanese Anime","Using Ref Images",get_image_path('./ironman.jpeg'),768,768
|
746 |
-
],
|
747 |
-
[1,0.5,0.5,3,"a knight in silver armor with blue cape",
|
748 |
-
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
749 |
-
array2string(["[NC]On a grassy battlefield #He raises his sword toward the enemy",
|
750 |
-
"charging forward on horseback",
|
751 |
-
"blocking an arrow with his shield",
|
752 |
-
"[NC]He wins the battle and is crowned by the king"]),
|
753 |
-
"Japanese Anime", "Using Ref Images",get_image_path('./taylor.png'),768,768
|
754 |
-
],
|
755 |
-
[0,0.5,0.5,3,"a girl with pink hair, school uniform",
|
756 |
-
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
757 |
-
array2string(["at the school gate",
|
758 |
-
"[NC]She notices a mysterious envelope in her locker",
|
759 |
-
"reading the letter in shock #It's a confession of love",
|
760 |
-
"running outside, blushing"
|
761 |
-
]),
|
762 |
-
"Japanese Anime","Only Using Textual Description",get_image_path('./yannlecun.png'),768,768
|
763 |
-
],
|
764 |
-
[0,0.3,0.5,3,"an astronaut in white spacesuit",
|
765 |
-
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
766 |
-
array2string([
|
767 |
-
"floating in space above Earth",
|
768 |
-
"[NC]Spots a mysterious alien ship in the distance",
|
769 |
-
"enters the ship cautiously",
|
770 |
-
"[NC]finds a message written in glowing symbols"]),
|
771 |
-
"Japanese Anime","Only Using Textual Description",get_image_path('./ironman.jpeg'),768,768
|
772 |
-
]
|
773 |
-
],
|
774 |
-
inputs=[seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt, prompt_array,style,model_type,files,G_height,G_width],
|
775 |
-
# outputs=[post_sketch, binary_matrixes, *color_row, *colors, *prompts, gen_prompt_vis, general_prompt, seed_],
|
776 |
-
# run_on_click=True,
|
777 |
label='😺 Examples 😺',
|
778 |
)
|
779 |
-
gr.Markdown(article)
|
780 |
|
781 |
-
|
782 |
|
783 |
demo.launch()
|
|
|
461 |
# pipe3.scheduler.set_timesteps(50)
|
462 |
######### Gradio Fuction #############
|
463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
def remove_tips():
|
465 |
return gr.update(visible=False)
|
466 |
|
467 |
def apply_style_positive(style_name: str, positive: str):
|
468 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
469 |
+
return p.replace("{prompt}", positive)
|
470 |
|
471 |
def apply_style(style_name: str, positives: list, negative: str = ""):
|
472 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
473 |
return [p.replace("{prompt}", positive) for positive in positives], n + ' ' + negative
|
474 |
|
475 |
+
def change_visible_by_model_type(_model_type):
|
476 |
+
# Since you are **only using text**, always hide ref image uploads
|
477 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
|
|
|
|
|
|
|
|
478 |
|
479 |
|
480 |
######### Image Generation ##############
|
481 |
@spaces.GPU(duration=120)
|
482 |
+
def process_generation(_sd_type, _num_steps, style_name, guidance_scale, seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt, prompt_array, G_height, G_width, _comic_type):
|
483 |
+
global sa32, sa64, id_length, total_length, attn_procs, unet, cur_model_type, device
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
global num_steps
|
485 |
global write
|
486 |
+
global cur_step, attn_count
|
487 |
+
global height, width
|
488 |
height = G_height
|
489 |
width = G_width
|
490 |
+
global pipe2, pipe4
|
491 |
+
global sd_model_path, models_dict
|
492 |
+
|
493 |
sd_model_path = models_dict[_sd_type]
|
494 |
+
num_steps = _num_steps
|
495 |
use_safe_tensor = True
|
496 |
+
|
497 |
+
if style_name == "(No style)":
|
498 |
sd_model_path = models_dict["SDXL"]
|
499 |
+
|
500 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(sd_model_path, torch_dtype=torch.float16)
|
501 |
+
pipe = pipe.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
502 |
pipe.enable_freeu(s1=0.6, s2=0.4, b1=1.1, b2=1.2)
|
503 |
+
set_attention_processor(pipe.unet, id_length_, is_ipadapter=False)
|
504 |
+
|
505 |
+
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
506 |
+
|
507 |
+
cur_model_type = _sd_type + "-original-" + str(id_length_)
|
508 |
+
|
509 |
prompts = prompt_array.splitlines()
|
510 |
+
if len(prompts) > 10:
|
511 |
+
raise gr.Error(f"No more than 10 prompts in the Hugging Face demo for speed! But found {len(prompts)} prompts!")
|
512 |
+
|
|
|
513 |
generator = torch.Generator(device="cuda").manual_seed(seed_)
|
514 |
+
sa32, sa64 = sa32_, sa64_
|
515 |
id_length = id_length_
|
516 |
clipped_prompts = prompts[:]
|
517 |
+
|
518 |
+
prompts = [general_prompt + "," + prompt if "[NC]" not in prompt else prompt.replace("[NC]", "") for prompt in clipped_prompts]
|
519 |
prompts = [prompt.rpartition('#')[0] if "#" in prompt else prompt for prompt in prompts]
|
520 |
+
|
521 |
id_prompts = prompts[:id_length]
|
522 |
real_prompts = prompts[id_length:]
|
523 |
+
|
524 |
torch.cuda.empty_cache()
|
525 |
write = True
|
526 |
cur_step = 0
|
|
|
527 |
attn_count = 0
|
528 |
+
|
529 |
id_prompts, negative_prompt = apply_style(style_name, id_prompts, negative_prompt)
|
530 |
+
|
531 |
setup_seed(seed_)
|
532 |
+
|
533 |
total_results = []
|
534 |
+
|
535 |
+
# Generate ID images
|
536 |
+
id_images = pipe(id_prompts, num_inference_steps=num_steps, guidance_scale=guidance_scale,
|
537 |
+
height=height, width=width, negative_prompt=negative_prompt, generator=generator).images
|
|
|
|
|
538 |
total_results = id_images + total_results
|
539 |
yield total_results
|
540 |
+
|
541 |
+
# Generate real comic images
|
542 |
real_images = []
|
543 |
write = False
|
544 |
for real_prompt in real_prompts:
|
545 |
setup_seed(seed_)
|
546 |
cur_step = 0
|
547 |
real_prompt = apply_style_positive(style_name, real_prompt)
|
548 |
+
|
549 |
+
real_images.append(pipe(real_prompt, num_inference_steps=num_steps, guidance_scale=guidance_scale,
|
550 |
+
height=height, width=width, negative_prompt=negative_prompt, generator=generator).images[0])
|
|
|
|
|
|
|
551 |
total_results = [real_images[-1]] + total_results
|
552 |
yield total_results
|
553 |
+
|
554 |
+
# Comic typesetting if selected
|
555 |
if _comic_type != "No typesetting (default)":
|
556 |
+
captions = prompt_array.splitlines()
|
557 |
+
captions = [caption.replace("[NC]", "") for caption in captions]
|
558 |
captions = [caption.split('#')[-1] if "#" in caption else caption for caption in captions]
|
559 |
from PIL import ImageFont
|
560 |
+
total_results = get_comic(id_images + real_images, _comic_type, captions=captions,
|
561 |
+
font=ImageFont.truetype("./Inkfree.ttf", int(45))) + total_results
|
|
|
|
|
|
|
|
|
|
|
562 |
|
563 |
+
yield total_results
|
564 |
|
565 |
def array2string(arr):
|
566 |
+
return "\n".join(arr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
567 |
|
568 |
#################################################
|
569 |
#################################################
|
|
|
572 |
binary_matrixes = gr.State([])
|
573 |
color_layout = gr.State([])
|
574 |
|
|
|
575 |
gr.Markdown(title)
|
576 |
gr.Markdown(description)
|
577 |
|
578 |
with gr.Row():
|
579 |
with gr.Group(elem_id="main-image"):
|
580 |
+
|
581 |
+
with gr.Column(visible=True):
|
582 |
+
sd_type = gr.Dropdown(choices=list(models_dict.keys()), value="SDXL", label="sd_type", info="Select pretrained model")
|
583 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
general_prompt = gr.Textbox(value='', label="(1) Textual Description for Character", interactive=True)
|
585 |
+
negative_prompt = gr.Textbox(value='', label="(2) Negative Prompt", interactive=True)
|
586 |
+
style = gr.Dropdown(label="Style Template", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
|
587 |
+
prompt_array = gr.Textbox(lines=3, value='', label="(3) Comic Description (each line = one frame)", interactive=True)
|
588 |
+
|
589 |
+
with gr.Accordion("(4) Tune the Hyperparameters", open=True):
|
590 |
+
sa32_ = gr.Slider(label="Paired Attention at 32x32 layers", minimum=0, maximum=1., value=0.7, step=0.1)
|
591 |
+
sa64_ = gr.Slider(label="Paired Attention at 64x64 layers", minimum=0, maximum=1., value=0.7, step=0.1)
|
592 |
+
id_length_ = gr.Slider(label="Number of id images", minimum=2, maximum=4, value=3, step=1)
|
|
|
593 |
seed_ = gr.Slider(label="Seed", minimum=-1, maximum=MAX_SEED, value=0, step=1)
|
594 |
+
num_steps = gr.Slider(label="Number of Sample Steps", minimum=25, maximum=50, step=1, value=50)
|
595 |
+
G_height = gr.Slider(label="Height", minimum=256, maximum=1024, step=32, value=1024)
|
596 |
+
G_width = gr.Slider(label="Width", minimum=256, maximum=1024, step=32, value=1024)
|
597 |
+
comic_type = gr.Radio(["No Typesetting (default)", "Four Panel", "Classic Comic Style"], value="Classic Comic Style", label="Typesetting Style")
|
598 |
+
guidance_scale = gr.Slider(label="Guidance Scale", minimum=0.1, maximum=10.0, step=0.1, value=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
599 |
|
600 |
+
final_run_btn = gr.Button("Generate ! 😺")
|
601 |
|
602 |
with gr.Column():
|
603 |
out_image = gr.Gallery(label="Result", columns=2, height='auto')
|
604 |
+
generated_information = gr.Markdown(label="Generation Details", value="", visible=False)
|
605 |
gr.Markdown(version)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
606 |
|
607 |
+
final_run_btn.click(fn=set_text_unfinished, outputs=generated_information
|
608 |
+
).then(
|
609 |
+
process_generation,
|
610 |
+
inputs=[sd_type, num_steps, style, guidance_scale, seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt, prompt_array, G_height, G_width, comic_type],
|
611 |
+
outputs=out_image
|
612 |
+
).then(fn=set_text_finished, outputs=generated_information)
|
613 |
|
614 |
gr.Examples(
|
615 |
examples=[
|
616 |
+
[0, 0.5, 0.5, 2, "a scientist, wearing a lab coat and glasses",
|
617 |
+
"bad anatomy, bad hands, missing fingers, ...",
|
618 |
+
array2string([
|
619 |
+
"In the lab, surrounded by bubbling beakers #Today I will discover something new",
|
620 |
+
"[NC]He discovers a glowing chemical compound #Wow!!!",
|
621 |
+
"[NC]The car on the road, near the forest #He drives to the forest in search of treasure.",
|
622 |
+
"startled, holding the beaker #The compound explodes with a bright light",
|
623 |
+
"[NC]He opens his eyes to find himself in a different world"
|
624 |
+
]),
|
625 |
+
"Comic book", 768, 768],
|
626 |
+
],
|
627 |
+
inputs=[seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt, prompt_array, style, G_height, G_width],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
628 |
label='😺 Examples 😺',
|
629 |
)
|
|
|
630 |
|
631 |
+
gr.Markdown(article)
|
632 |
|
633 |
demo.launch()
|