Skip to content

Commit 18eaa77

Browse files
committed
example
1 parent 8d65382 commit 18eaa77

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

src/diffusers/pipelines/controlnet/pipeline_controlnet_union_sd_xl.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,45 +67,40 @@
6767
EXAMPLE_DOC_STRING = """
6868
Examples:
6969
```py
70-
>>> # !pip install opencv-python transformers accelerate
71-
>>> from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel, AutoencoderKL
70+
>>> # !pip install controlnet_aux
71+
>>> from controlnet_aux import LineartAnimeDetector
72+
>>> from diffusers import StableDiffusionXLControlNetPipeline, ControlNetUnionModel, AutoencoderKL
73+
>>> from diffusers.models.controlnets import ControlNetUnionInput
7274
>>> from diffusers.utils import load_image
73-
>>> import numpy as np
7475
>>> import torch
75-
76-
>>> import cv2
77-
>>> from PIL import Image
78-
79-
>>> prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting"
80-
>>> negative_prompt = "low quality, bad quality, sketches"
81-
76+
>>> prompt = "A cat"
8277
>>> # download an image
8378
>>> image = load_image(
84-
... "https://hf.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png"
85-
... )
86-
79+
... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
80+
... ).resize((1024, 1024))
8781
>>> # initialize the models and pipeline
88-
>>> controlnet_conditioning_scale = 0.5 # recommended for good generalization
89-
>>> controlnet = ControlNetModel.from_pretrained(
90-
... "diffusers/controlnet-canny-sdxl-1.0", torch_dtype=torch.float16
82+
>>> controlnet = ControlNetUnionModel.from_pretrained(
83+
... "xinsir/controlnet-union-sdxl-1.0", torch_dtype=torch.float16
84+
... )
85+
>>> vae = AutoencoderKL.from_pretrained(
86+
... "madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
9187
... )
92-
>>> vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
9388
>>> pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
94-
... "stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnet, vae=vae, torch_dtype=torch.float16
89+
... "stabilityai/stable-diffusion-xl-base-1.0",
90+
... controlnet=controlnet,
91+
... vae=vae,
92+
... torch_dtype=torch.float16,
9593
... )
9694
>>> pipe.enable_model_cpu_offload()
97-
98-
>>> # get canny image
99-
>>> image = np.array(image)
100-
>>> image = cv2.Canny(image, 100, 200)
101-
>>> image = image[:, :, None]
102-
>>> image = np.concatenate([image, image, image], axis=2)
103-
>>> canny_image = Image.fromarray(image)
104-
95+
>>> # prepare image
96+
>>> processor = LineartAnimeDetector.from_pretrained("lllyasviel/Annotators")
97+
>>> controlnet_img = processor(image, output_type="pil")
98+
>>> # set ControlNetUnion input
99+
>>> union_input = ControlNetUnionInput(
100+
... canny=controlnet_img,
101+
... )
105102
>>> # generate image
106-
>>> image = pipe(
107-
... prompt, controlnet_conditioning_scale=controlnet_conditioning_scale, image=canny_image
108-
... ).images[0]
103+
>>> image = pipe(prompt, image=union_input).images[0]
109104
```
110105
"""
111106

0 commit comments

Comments
 (0)