Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -106,22 +106,27 @@ def infer(
|
|
106 |
seed=4,
|
107 |
guidance_scale=7.5,
|
108 |
lora_scale=0.7,
|
109 |
-
strength_cn=0.5, # Коэфф. зашумления ControlNet
|
110 |
use_control_net=False, # Параметр для включения ControlNet
|
|
|
|
|
111 |
control_strength=0.5, # Сила влияния ControlNet
|
112 |
cn_source_image=None, # Исходное изображение ControlNet
|
113 |
control_image=None, # Контрольное изображение ControlNet
|
114 |
-
strength_ip=0.5, # Коэфф. зашумления IP_adapter
|
115 |
use_ip_adapter=False, # Параметр для включения IP_adapter
|
|
|
|
|
116 |
ip_adapter_strength=0.5,# Сила влияния IP_adapter
|
117 |
ip_source_image=None, # Исходное изображение IP_adapter
|
118 |
ip_adapter_image=None, # Контрольное изображение IP_adapter
|
119 |
progress=gr.Progress(track_tqdm=True)
|
120 |
):
|
121 |
-
generator = torch.Generator(device).manual_seed(seed)
|
122 |
|
|
|
|
|
|
|
|
|
123 |
# Генерация изображений с Ip_Adapter ------------------------------------------------------------------------------------------------------------------
|
124 |
-
if use_ip_adapter and ip_source_image is not None and ip_adapter_image is not None:
|
125 |
|
126 |
# Режим pose_estimation ---------------------------------------------------------------------------------------------------------------------------
|
127 |
# prompt = "A man runs through the park against the background of trees. The man's entire figure, face, arms and legs are visible. Anime style. The best quality."
|
@@ -146,6 +151,8 @@ def infer(
|
|
146 |
|
147 |
if ip_adapter_mode.value == "pose_estimation":
|
148 |
|
|
|
|
|
149 |
# Инициализация ControlNet
|
150 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch_dtype)
|
151 |
|
@@ -233,13 +240,14 @@ def infer(
|
|
233 |
|
234 |
if ip_adapter_mode.value == "edge_detection":
|
235 |
|
|
|
|
|
236 |
# Инициализация ControlNet
|
237 |
controlnet_model_path = "lllyasviel/control_v11f1p_sd15_depth"
|
238 |
controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch.float16)
|
239 |
|
240 |
generator = torch.Generator(device).manual_seed(seed)
|
241 |
|
242 |
-
|
243 |
pipe_ip_adapter = StableDiffusionControlNetPipeline.from_pretrained(
|
244 |
model_default,
|
245 |
controlnet=controlnet,
|
@@ -338,6 +346,9 @@ def infer(
|
|
338 |
|
339 |
if ip_adapter_mode.value == "depth_map":
|
340 |
|
|
|
|
|
|
|
341 |
# Инициализация ControlNet
|
342 |
controlnet_model_path = "lllyasviel/control_v11f1p_sd15_depth"
|
343 |
controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch.float16)
|
@@ -365,7 +376,7 @@ def infer(
|
|
365 |
).images[0]
|
366 |
else:
|
367 |
# Генерация изображений с ControlNet ----------------------------------------------------------------------------------------------------------------
|
368 |
-
if use_control_net and control_image is not None and cn_source_image is not None:
|
369 |
|
370 |
# Режим pose_estimation ---------------------------------------------------------------------------------------------------------------------------
|
371 |
# prompt = "A man runs through the park against the background of trees. The man's entire figure, face, arms and legs are visible. Anime style. The best quality."
|
@@ -389,6 +400,8 @@ def infer(
|
|
389 |
|
390 |
if control_mode.value == "pose_estimation":
|
391 |
|
|
|
|
|
392 |
# Инициализация ControlNet
|
393 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch_dtype)
|
394 |
|
@@ -472,6 +485,8 @@ def infer(
|
|
472 |
|
473 |
if control_mode.value == "edge_detection":
|
474 |
|
|
|
|
|
475 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16, use_safetensors=True)
|
476 |
|
477 |
generator = torch.Generator(device).manual_seed(seed)
|
@@ -521,6 +536,8 @@ def infer(
|
|
521 |
|
522 |
if control_mode.value == "depth_map":
|
523 |
|
|
|
|
|
524 |
depth_estimator = pipeline("depth-estimation")
|
525 |
depth_map = get_depth_map(control_image, depth_estimator).unsqueeze(0).half().to(device)
|
526 |
|
@@ -811,13 +828,15 @@ with gr.Blocks(css=css) as demo:
|
|
811 |
seed,
|
812 |
guidance_scale,
|
813 |
lora_scale,
|
|
|
|
|
814 |
strength_cn, # Коэфф. зашумления ControlNet
|
815 |
-
|
816 |
-
control_strength, # Контроль силы ControlNet
|
817 |
cn_source_image, # Исходное изображение ControlNet
|
818 |
control_image, # Контрольное изображение ControlNet
|
819 |
-
strength_ip, # Коэфф. зашумления IP_adapter
|
820 |
use_ip_adapter, # Параметр для включения IP_adapter
|
|
|
|
|
821 |
ip_adapter_strength,# Сила влияния IP_adapter
|
822 |
ip_source_image, # Исходное изображение IP_adapter
|
823 |
ip_adapter_image, # Контрольное изображение IP_adapter
|
|
|
106 |
seed=4,
|
107 |
guidance_scale=7.5,
|
108 |
lora_scale=0.7,
|
|
|
109 |
use_control_net=False, # Параметр для включения ControlNet
|
110 |
+
control_mode=None, # Параметр для выбора режима ControlNet
|
111 |
+
strength_cn=0.5, # Коэфф. зашумления ControlNet
|
112 |
control_strength=0.5, # Сила влияния ControlNet
|
113 |
cn_source_image=None, # Исходное изображение ControlNet
|
114 |
control_image=None, # Контрольное изображение ControlNet
|
|
|
115 |
use_ip_adapter=False, # Параметр для включения IP_adapter
|
116 |
+
ip_adapter_mode=None, # Параметр для выбора режима IP_adapter
|
117 |
+
strength_ip=0.5, # Коэфф. зашумления IP_adapter
|
118 |
ip_adapter_strength=0.5,# Сила влияния IP_adapter
|
119 |
ip_source_image=None, # Исходное изображение IP_adapter
|
120 |
ip_adapter_image=None, # Контрольное изображение IP_adapter
|
121 |
progress=gr.Progress(track_tqdm=True)
|
122 |
):
|
|
|
123 |
|
124 |
+
|
125 |
+
print('ip_adapter_mode.value = ', ip_adapter_mode.value)
|
126 |
+
print('control_mode.value = ', control_mode.value)
|
127 |
+
|
128 |
# Генерация изображений с Ip_Adapter ------------------------------------------------------------------------------------------------------------------
|
129 |
+
if use_ip_adapter: #and ip_source_image is not None and ip_adapter_image is not None:
|
130 |
|
131 |
# Режим pose_estimation ---------------------------------------------------------------------------------------------------------------------------
|
132 |
# prompt = "A man runs through the park against the background of trees. The man's entire figure, face, arms and legs are visible. Anime style. The best quality."
|
|
|
151 |
|
152 |
if ip_adapter_mode.value == "pose_estimation":
|
153 |
|
154 |
+
print('ip_adapter_mode.value = ', ip_adapter_mode.value)
|
155 |
+
|
156 |
# Инициализация ControlNet
|
157 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch_dtype)
|
158 |
|
|
|
240 |
|
241 |
if ip_adapter_mode.value == "edge_detection":
|
242 |
|
243 |
+
print('ip_adapter_mode.value = ', ip_adapter_mode.value)
|
244 |
+
|
245 |
# Инициализация ControlNet
|
246 |
controlnet_model_path = "lllyasviel/control_v11f1p_sd15_depth"
|
247 |
controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch.float16)
|
248 |
|
249 |
generator = torch.Generator(device).manual_seed(seed)
|
250 |
|
|
|
251 |
pipe_ip_adapter = StableDiffusionControlNetPipeline.from_pretrained(
|
252 |
model_default,
|
253 |
controlnet=controlnet,
|
|
|
346 |
|
347 |
if ip_adapter_mode.value == "depth_map":
|
348 |
|
349 |
+
print('ip_adapter_mode.value = ', ip_adapter_mode.value)
|
350 |
+
|
351 |
+
|
352 |
# Инициализация ControlNet
|
353 |
controlnet_model_path = "lllyasviel/control_v11f1p_sd15_depth"
|
354 |
controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch.float16)
|
|
|
376 |
).images[0]
|
377 |
else:
|
378 |
# Генерация изображений с ControlNet ----------------------------------------------------------------------------------------------------------------
|
379 |
+
if use_control_net: #and control_image is not None and cn_source_image is not None:
|
380 |
|
381 |
# Режим pose_estimation ---------------------------------------------------------------------------------------------------------------------------
|
382 |
# prompt = "A man runs through the park against the background of trees. The man's entire figure, face, arms and legs are visible. Anime style. The best quality."
|
|
|
400 |
|
401 |
if control_mode.value == "pose_estimation":
|
402 |
|
403 |
+
print('control_mode.value = ', control_mode.value)
|
404 |
+
|
405 |
# Инициализация ControlNet
|
406 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch_dtype)
|
407 |
|
|
|
485 |
|
486 |
if control_mode.value == "edge_detection":
|
487 |
|
488 |
+
print('control_mode.value = ', control_mode.value)
|
489 |
+
|
490 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16, use_safetensors=True)
|
491 |
|
492 |
generator = torch.Generator(device).manual_seed(seed)
|
|
|
536 |
|
537 |
if control_mode.value == "depth_map":
|
538 |
|
539 |
+
print('control_mode.value = ', control_mode.value)
|
540 |
+
|
541 |
depth_estimator = pipeline("depth-estimation")
|
542 |
depth_map = get_depth_map(control_image, depth_estimator).unsqueeze(0).half().to(device)
|
543 |
|
|
|
828 |
seed,
|
829 |
guidance_scale,
|
830 |
lora_scale,
|
831 |
+
use_control_net, # Параметр для включения ControlNet
|
832 |
+
control_mode, # Параметр для выбора режима ControlNet
|
833 |
strength_cn, # Коэфф. зашумления ControlNet
|
834 |
+
control_strength, # Сила влияния ControlNet
|
|
|
835 |
cn_source_image, # Исходное изображение ControlNet
|
836 |
control_image, # Контрольное изображение ControlNet
|
|
|
837 |
use_ip_adapter, # Параметр для включения IP_adapter
|
838 |
+
ip_adapter_mode, # Параметр для выбора режима IP_adapter
|
839 |
+
strength_ip, # Коэфф. зашумления IP_adapter
|
840 |
ip_adapter_strength,# Сила влияния IP_adapter
|
841 |
ip_source_image, # Исходное изображение IP_adapter
|
842 |
ip_adapter_image, # Контрольное изображение IP_adapter
|