Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -101,10 +101,37 @@ def infer(
|
|
101 |
source_image = preprocess_image(source_image, width, height)
|
102 |
control_image = preprocess_image(control_image, width, height)
|
103 |
|
104 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
image = pipe_controlnet(
|
106 |
-
|
107 |
-
|
108 |
image=source_image,
|
109 |
control_image=control_image,
|
110 |
width=width,
|
|
|
101 |
source_image = preprocess_image(source_image, width, height)
|
102 |
control_image = preprocess_image(control_image, width, height)
|
103 |
|
104 |
+
# Создаём пайплайн ControlNet с LoRA, если он ещё не создан
|
105 |
+
if not hasattr(pipe_controlnet, 'lora_loaded') or not pipe_controlnet.lora_loaded:
|
106 |
+
# Загружаем LoRA для UNet
|
107 |
+
pipe_controlnet.unet = PeftModel.from_pretrained(
|
108 |
+
pipe_controlnet.unet,
|
109 |
+
'./lora_man_animestyle/unet',
|
110 |
+
adapter_name="default"
|
111 |
+
)
|
112 |
+
pipe_controlnet.unet.set_adapter("default")
|
113 |
+
|
114 |
+
# Загружаем LoRA для Text Encoder, если она существует
|
115 |
+
text_encoder_lora_path = './lora_man_animestyle/text_encoder'
|
116 |
+
if os.path.exists(text_encoder_lora_path):
|
117 |
+
pipe_controlnet.text_encoder = PeftModel.from_pretrained(
|
118 |
+
pipe_controlnet.text_encoder,
|
119 |
+
text_encoder_lora_path,
|
120 |
+
adapter_name="default"
|
121 |
+
)
|
122 |
+
pipe_controlnet.text_encoder.set_adapter("default")
|
123 |
+
|
124 |
+
# Объединяем LoRA с основной моделью
|
125 |
+
pipe_controlnet.fuse_lora(lora_scale=lora_scale)
|
126 |
+
pipe_controlnet.lora_loaded = True # Помечаем, что LoRA загружена
|
127 |
+
|
128 |
+
# Используем ControlNet с LoRA
|
129 |
+
prompt_embeds = long_prompt_encoder(prompt, pipe.tokenizer, pipe.text_encoder)
|
130 |
+
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
131 |
+
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
132 |
image = pipe_controlnet(
|
133 |
+
prompt_embeds=prompt_embeds,
|
134 |
+
negative_prompt_embeds=negative_prompt_embeds,
|
135 |
image=source_image,
|
136 |
control_image=control_image,
|
137 |
width=width,
|