Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -84,22 +84,12 @@ def preprocess_image(image, target_width, target_height, resize_to_224=False):
|
|
84 |
image = torch.from_numpy(image).to(device)
|
85 |
return image
|
86 |
|
87 |
-
# def get_depth_map(image, depth_estimator):
|
88 |
-
# image = depth_estimator(image)["depth"]
|
89 |
-
# image = np.array(image)
|
90 |
-
# image = image[:, :, None]
|
91 |
-
# image = np.concatenate([image, image, image], axis=2)
|
92 |
-
# detected_map = torch.from_numpy(image).float() / 255.0
|
93 |
-
# depth_map = detected_map.permute(2, 0, 1)
|
94 |
-
# return depth_map
|
95 |
-
|
96 |
def get_depth_map(image, depth_estimator):
|
97 |
# Преобразуем изображение в PIL, если это необходимо
|
98 |
if isinstance(image, np.ndarray):
|
99 |
image = Image.fromarray(image)
|
100 |
elif isinstance(image, torch.Tensor):
|
101 |
image = Image.fromarray(image.cpu().numpy())
|
102 |
-
|
103 |
# Получаем карту глубины
|
104 |
depth_map = depth_estimator(image)["depth"]
|
105 |
depth_map = np.array(depth_map)
|
@@ -411,7 +401,7 @@ def infer(
|
|
411 |
pipe_controlnet = StableDiffusionControlNetPipeline.from_pretrained(
|
412 |
"stable-diffusion-v1-5/stable-diffusion-v1-5",
|
413 |
controlnet=controlnet,
|
414 |
-
torch_dtype=
|
415 |
use_safetensors=True
|
416 |
).to(device)
|
417 |
|
@@ -440,10 +430,6 @@ def infer(
|
|
440 |
|
441 |
print('control_mode = ', control_mode)
|
442 |
|
443 |
-
# # Преобразуем изображения
|
444 |
-
# cn_source_image = preprocess_image(cn_source_image, width, height)
|
445 |
-
# control_image = preprocess_image(control_image, width, height)
|
446 |
-
|
447 |
depth_estimator = pipeline("depth-estimation")
|
448 |
depth_map = get_depth_map(control_image, depth_estimator).unsqueeze(0).half().to(device)
|
449 |
|
@@ -455,7 +441,7 @@ def infer(
|
|
455 |
pipe_controlnet = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
456 |
"stable-diffusion-v1-5/stable-diffusion-v1-5",
|
457 |
controlnet=controlnet,
|
458 |
-
torch_dtype=
|
459 |
use_safetensors=True
|
460 |
).to(device)
|
461 |
|
|
|
84 |
image = torch.from_numpy(image).to(device)
|
85 |
return image
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
def get_depth_map(image, depth_estimator):
|
88 |
# Преобразуем изображение в PIL, если это необходимо
|
89 |
if isinstance(image, np.ndarray):
|
90 |
image = Image.fromarray(image)
|
91 |
elif isinstance(image, torch.Tensor):
|
92 |
image = Image.fromarray(image.cpu().numpy())
|
|
|
93 |
# Получаем карту глубины
|
94 |
depth_map = depth_estimator(image)["depth"]
|
95 |
depth_map = np.array(depth_map)
|
|
|
401 |
pipe_controlnet = StableDiffusionControlNetPipeline.from_pretrained(
|
402 |
"stable-diffusion-v1-5/stable-diffusion-v1-5",
|
403 |
controlnet=controlnet,
|
404 |
+
torch_dtype=torch_dtype,
|
405 |
use_safetensors=True
|
406 |
).to(device)
|
407 |
|
|
|
430 |
|
431 |
print('control_mode = ', control_mode)
|
432 |
|
|
|
|
|
|
|
|
|
433 |
depth_estimator = pipeline("depth-estimation")
|
434 |
depth_map = get_depth_map(control_image, depth_estimator).unsqueeze(0).half().to(device)
|
435 |
|
|
|
441 |
pipe_controlnet = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
442 |
"stable-diffusion-v1-5/stable-diffusion-v1-5",
|
443 |
controlnet=controlnet,
|
444 |
+
torch_dtype=torch_dtype,
|
445 |
use_safetensors=True
|
446 |
).to(device)
|
447 |
|