Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -523,42 +523,64 @@ def infer(
|
|
| 523 |
}
|
| 524 |
|
| 525 |
image = pipe(**params).images[0]
|
| 526 |
-
|
| 527 |
-
|
| 528 |
else:
|
| 529 |
-
|
| 530 |
-
# Генерация изображений с LORA без ControlNet и IP_Adapter ---------------------------------------------------------------------------------------------
|
| 531 |
|
| 532 |
-
|
| 533 |
-
controlnet_model_path = "lllyasviel/sd-controlnet-openpose"
|
| 534 |
-
controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch_dtype)
|
| 535 |
|
| 536 |
-
|
|
|
|
|
|
|
|
|
|
| 537 |
|
| 538 |
-
if model != model_default:
|
| 539 |
-
pipe = StableDiffusionPipeline.from_pretrained(model, torch_dtype=torch_dtype).to(device)
|
| 540 |
-
prompt_embeds = long_prompt_encoder(prompt, pipe.tokenizer, pipe.text_encoder)
|
| 541 |
-
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
| 542 |
-
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
| 543 |
-
else:
|
| 544 |
-
pipe_default = get_lora_sd_pipeline(lora_dir='lora_man_animestyle', base_model_name_or_path=model_default, dtype=torch_dtype).to(device)
|
| 545 |
-
pipe = pipe_default
|
| 546 |
prompt_embeds = long_prompt_encoder(prompt, pipe.tokenizer, pipe.text_encoder)
|
| 547 |
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
| 548 |
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
| 549 |
-
pipe.fuse_lora(lora_scale=lora_scale)
|
| 550 |
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
|
| 561 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
# Если выбрано удаление фона
|
| 564 |
if remove_bg:
|
|
@@ -780,8 +802,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 780 |
inputs=use_ip_adapter,
|
| 781 |
outputs=ip_adapter_options
|
| 782 |
)
|
| 783 |
-
# ---------------------------------------------------------------------------------------------------------
|
| 784 |
|
|
|
|
| 785 |
# Checkbox для удаления фона
|
| 786 |
remove_bg = gr.Checkbox(
|
| 787 |
label="Remove Background",
|
|
@@ -813,13 +835,20 @@ with gr.Blocks(css=css) as demo:
|
|
| 813 |
inputs=use_LCM_adapter,
|
| 814 |
outputs=LCM_adapter
|
| 815 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 816 |
# ---------------------------------------------------------------------------------------------------------
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
-
|
| 823 |
|
| 824 |
|
| 825 |
gr.Examples(examples=examples, inputs=[prompt], label="Examples for prompt:")
|
|
|
|
| 523 |
}
|
| 524 |
|
| 525 |
image = pipe(**params).images[0]
|
|
|
|
|
|
|
| 526 |
else:
|
| 527 |
+
# Генерация изображений с DDIMScheduler ---------------------------------------------------------------------------------------------
|
|
|
|
| 528 |
|
| 529 |
+
if use_DDIMScheduler:
|
|
|
|
|
|
|
| 530 |
|
| 531 |
+
generator = torch.Generator(device).manual_seed(seed)
|
| 532 |
+
|
| 533 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_default, torch_dtype=torch_dtype).to(device)
|
| 534 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
prompt_embeds = long_prompt_encoder(prompt, pipe.tokenizer, pipe.text_encoder)
|
| 537 |
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
| 538 |
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
|
|
|
| 539 |
|
| 540 |
+
params = {
|
| 541 |
+
'prompt_embeds': prompt_embeds,
|
| 542 |
+
'negative_prompt_embeds': negative_prompt_embeds,
|
| 543 |
+
'guidance_scale': guidance_scale,
|
| 544 |
+
'num_inference_steps': num_inference_steps,
|
| 545 |
+
'width': width,
|
| 546 |
+
'height': height,
|
| 547 |
+
'generator': generator,
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
image = pipe(**params).images[0]
|
| 551 |
+
else:
|
| 552 |
+
# Генерация изображений с LORA без ControlNet и IP_Adapter ---------------------------------------------------------------------------------------------
|
| 553 |
|
| 554 |
+
# Инициализация ControlNet
|
| 555 |
+
controlnet_model_path = "lllyasviel/sd-controlnet-openpose"
|
| 556 |
+
controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch_dtype)
|
| 557 |
+
|
| 558 |
+
generator = torch.Generator(device).manual_seed(seed)
|
| 559 |
+
|
| 560 |
+
if model != model_default:
|
| 561 |
+
pipe = StableDiffusionPipeline.from_pretrained(model, torch_dtype=torch_dtype).to(device)
|
| 562 |
+
prompt_embeds = long_prompt_encoder(prompt, pipe.tokenizer, pipe.text_encoder)
|
| 563 |
+
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
| 564 |
+
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
| 565 |
+
else:
|
| 566 |
+
pipe_default = get_lora_sd_pipeline(lora_dir='lora_man_animestyle', base_model_name_or_path=model_default, dtype=torch_dtype).to(device)
|
| 567 |
+
pipe = pipe_default
|
| 568 |
+
prompt_embeds = long_prompt_encoder(prompt, pipe.tokenizer, pipe.text_encoder)
|
| 569 |
+
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
| 570 |
+
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
| 571 |
+
pipe.fuse_lora(lora_scale=lora_scale)
|
| 572 |
+
|
| 573 |
+
params = {
|
| 574 |
+
'prompt_embeds': prompt_embeds,
|
| 575 |
+
'negative_prompt_embeds': negative_prompt_embeds,
|
| 576 |
+
'guidance_scale': guidance_scale,
|
| 577 |
+
'num_inference_steps': num_inference_steps,
|
| 578 |
+
'width': width,
|
| 579 |
+
'height': height,
|
| 580 |
+
'generator': generator,
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
image = pipe(**params).images[0]
|
| 584 |
|
| 585 |
# Если выбрано удаление фона
|
| 586 |
if remove_bg:
|
|
|
|
| 802 |
inputs=use_ip_adapter,
|
| 803 |
outputs=ip_adapter_options
|
| 804 |
)
|
|
|
|
| 805 |
|
| 806 |
+
# Удаление фона-----------------------------------------------------------------------------------------------
|
| 807 |
# Checkbox для удаления фона
|
| 808 |
remove_bg = gr.Checkbox(
|
| 809 |
label="Remove Background",
|
|
|
|
| 835 |
inputs=use_LCM_adapter,
|
| 836 |
outputs=LCM_adapter
|
| 837 |
)
|
| 838 |
+
|
| 839 |
+
# DDIMScheduler ------------------------------------------------------------------------------------------------
|
| 840 |
+
# Checkbox для DDIMScheduler
|
| 841 |
+
use_DDIMScheduler = gr.Checkbox(
|
| 842 |
+
label="DDIMScheduler",
|
| 843 |
+
value=False,
|
| 844 |
+
interactive=True
|
| 845 |
+
)
|
| 846 |
# ---------------------------------------------------------------------------------------------------------
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
|
|
|
| 852 |
|
| 853 |
|
| 854 |
gr.Examples(examples=examples, inputs=[prompt], label="Examples for prompt:")
|