forked from william-murray1204/stable-diffusion-cpp-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_controlnet.py
More file actions
43 lines (31 loc) · 1.24 KB
/
test_controlnet.py
File metadata and controls
43 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import traceback
from stable_diffusion_cpp import StableDiffusion
MODEL_PATH = "C:\\stable-diffusion\\v1-5-pruned-emaonly.safetensors"
CONTROLNET_MODEL_PATH = "C:\\stable-diffusion\\control_nets\\control_openpose-fp16.safetensors"
INPUT_IMAGE_PATH = "assets\\input.png"
stable_diffusion = StableDiffusion(model_path=MODEL_PATH, control_net_path=CONTROLNET_MODEL_PATH)
def callback(step: int, steps: int, time: float):
print("Completed step: {} of {}".format(step, steps))
try:
prompts = [
{"add": "", "prompt": "a lovely cat", "canny": False},
{"add": "_canny", "prompt": "a lovely cat", "canny": True},
]
for prompt in prompts:
# Generate images
images = stable_diffusion.txt_to_img(
prompt=prompt["prompt"],
control_cond=INPUT_IMAGE_PATH,
canny=prompt["canny"],
progress_callback=callback,
)
OUTPUT_DIR = "tests/outputs"
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
# Save images
for i, image in enumerate(images):
image.save(f"{OUTPUT_DIR}/controlnet{prompt['add']}_{i}.png")
except Exception as e:
traceback.print_exc()
print("Test - controlnet failed: ", e)