Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -136,14 +136,38 @@ def infer(
|
|
136 |
ip_source_image = preprocess_image(ip_source_image, width, height, resize_to_224=True)
|
137 |
ip_adapter_image = preprocess_image(ip_adapter_image, width, height, resize_to_224=True)
|
138 |
|
139 |
-
#
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
|
|
|
|
|
|
|
|
142 |
# Генерация изображения с использованием IP-Adapter
|
143 |
prompt_embeds = long_prompt_encoder(prompt, pipe_ip_adapter.tokenizer, pipe_ip_adapter.text_encoder)
|
144 |
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe_ip_adapter.tokenizer, pipe_ip_adapter.text_encoder)
|
145 |
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
146 |
-
|
147 |
image = pipe_ip_adapter(
|
148 |
prompt_embeds=prompt_embeds,
|
149 |
negative_prompt_embeds=negative_prompt_embeds,
|
@@ -156,7 +180,6 @@ def infer(
|
|
156 |
guidance_scale=guidance_scale,
|
157 |
controlnet_conditioning_scale=1.0,
|
158 |
generator=generator,
|
159 |
-
#image_embeds=image_embeds, # Передача эмбеддингов изображения
|
160 |
).images[0]
|
161 |
else:
|
162 |
# Генерация с ControlNet
|
|
|
136 |
ip_source_image = preprocess_image(ip_source_image, width, height, resize_to_224=True)
|
137 |
ip_adapter_image = preprocess_image(ip_adapter_image, width, height, resize_to_224=True)
|
138 |
|
139 |
+
# Создаём пайплайн IP_adapter с LoRA, если он ещё не создан ???????????????????????????????????????????????????????????????
|
140 |
+
if not hasattr(pipe_ip_adapter, 'lora_loaded') or not pipe_ip_adapter.lora_loaded:
|
141 |
+
# Загружаем LoRA для UNet
|
142 |
+
pipe_ip_adapter.unet = PeftModel.from_pretrained(
|
143 |
+
pipe_ip_adapter.unet,
|
144 |
+
'./lora_man_animestyle/unet',
|
145 |
+
adapter_name="default"
|
146 |
+
)
|
147 |
+
pipe_ip_adapter.unet.set_adapter("default")
|
148 |
+
|
149 |
+
# Загружаем LoRA для Text Encoder, если она существует
|
150 |
+
text_encoder_lora_path = './lora_man_animestyle/text_encoder'
|
151 |
+
if os.path.exists(text_encoder_lora_path):
|
152 |
+
pipe_ip_adapter.text_encoder = PeftModel.from_pretrained(
|
153 |
+
pipe_ip_adapter.text_encoder,
|
154 |
+
text_encoder_lora_path,
|
155 |
+
adapter_name="default"
|
156 |
+
)
|
157 |
+
pipe_ip_adapter.text_encoder.set_adapter("default")
|
158 |
+
|
159 |
+
# Объединяем LoRA с основной моделью
|
160 |
+
pipe_ip_adapter.fuse_lora(lora_scale=lora_scale)
|
161 |
+
pipe_ip_adapter.lora_loaded = True # Помечаем, что LoRA загружена
|
162 |
|
163 |
+
# Убедимся, что ip_adapter_strength имеет тип float
|
164 |
+
ip_adapter_strength = float(ip_adapter_strength)
|
165 |
+
#strength_ip = float(strength_ip)
|
166 |
+
|
167 |
# Генерация изображения с использованием IP-Adapter
|
168 |
prompt_embeds = long_prompt_encoder(prompt, pipe_ip_adapter.tokenizer, pipe_ip_adapter.text_encoder)
|
169 |
negative_prompt_embeds = long_prompt_encoder(negative_prompt, pipe_ip_adapter.tokenizer, pipe_ip_adapter.text_encoder)
|
170 |
prompt_embeds, negative_prompt_embeds = align_embeddings(prompt_embeds, negative_prompt_embeds)
|
|
|
171 |
image = pipe_ip_adapter(
|
172 |
prompt_embeds=prompt_embeds,
|
173 |
negative_prompt_embeds=negative_prompt_embeds,
|
|
|
180 |
guidance_scale=guidance_scale,
|
181 |
controlnet_conditioning_scale=1.0,
|
182 |
generator=generator,
|
|
|
183 |
).images[0]
|
184 |
else:
|
185 |
# Генерация с ControlNet
|