-
-
Save AlexeyLugovoy/d131f2d6c1a20c11c40311af904df27d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel, AutoencoderKL | |
from diffusers.utils import load_image | |
import numpy as np | |
import torch | |
import cv2 | |
from PIL import Image | |
img_canny = np.array(img_pil).copy() | |
img_canny = cv2.Canny(img_canny, 100, 300) | |
img_canny = img_canny[:, :, None] | |
img_canny = np.concatenate([img_canny, img_canny, img_canny], axis=2) | |
img_canny = Image.fromarray(img_canny) | |
controlnet = ControlNetModel.from_pretrained( | |
"diffusers/controlnet-canny-sdxl-1.0", | |
torch_dtype=torch.float16, | |
cache_dir=CACHE_DIR | |
).to(DEVICE) | |
pipe = StableDiffusionXLControlNetPipeline.from_pretrained( | |
"stabilityai/stable-diffusion-xl-base-1.0", | |
controlnet=controlnet, | |
torch_dtype=torch.float16, | |
cache_dir=CACHE_DIR | |
).to(DEVICE) | |
prompt = ["New modern style of livingroom, warm color palette, detailed, 8k"] | |
negative_prompt = ["low quality, bad quality, sketches"] | |
img_gen = pipe( | |
prompt, | |
negative_prompt=negative_prompt, | |
image=img_canny, | |
controlnet_conditioning_scale=0.6, | |
guidance_scale=9, | |
eta=0.0, | |
generator=torch.Generator(DEVICE).manual_seed(2), | |
num_inference_steps=100 | |
) | |
img_gen.images[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment