Views
No views yet
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
1import torch
2from diffusers.utils import load_image
3
4# https://github.com/huggingface/diffusers/pull/12215
5# pip install git+https://github.com/huggingface/diffusers
6from diffusers import QwenImageControlNetPipeline, QwenImageControlNetModel
7
8base_model = "Qwen/Qwen-Image"
9controlnet_model = "InstantX/Qwen-Image-ControlNet-Union"
10
11controlnet = QwenImageControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16)
12
13pipe = QwenImageControlNetPipeline.from_pretrained(
14 base_model, controlnet=controlnet, torch_dtype=torch.bfloat16
15)
16pipe.to("cuda")
17
18# canny
19# it is highly suggested to add 'TEXT' into prompt if there are text elements
20control_image = load_image("conds/canny.png")
21prompt = "Aesthetics art, traditional asian pagoda, elaborate golden accents, sky blue and white color palette, swirling cloud pattern, digital illustration, east asian architecture, ornamental rooftop, intricate detailing on building, cultural representation."
22controlnet_conditioning_scale = 1.0
23
24# soft edge
25# control_image = load_image("conds/soft_edge.png")
26# prompt = "Photograph of a young man with light brown hair jumping mid-air off a large, reddish-brown rock. He's wearing a navy blue sweater, light blue shirt, gray pants, and brown shoes. His arms are outstretched, and he has a slight smile on his face. The background features a cloudy sky and a distant, leafless tree line. The grass around the rock is patchy."
27# controlnet_conditioning_scale = 1.0
28
29# depth
30# control_image = load_image("conds/depth.png")
31# prompt = "A swanky, minimalist living room with a huge floor-to-ceiling window letting in loads of natural light. A beige couch with white cushions sits on a wooden floor, with a matching coffee table in front. The walls are a soft, warm beige, decorated with two framed botanical prints. A potted plant chills in the corner near the window. Sunlight pours through the leaves outside, casting cool shadows on the floor."
32# controlnet_conditioning_scale = 1.0
33
34# pose
35# control_image = load_image("conds/pose.png")
36# prompt = "Photograph of a young man with light brown hair and a beard, wearing a beige flat cap, black leather jacket, gray shirt, brown pants, and white sneakers. He's sitting on a concrete ledge in front of a large circular window, with a cityscape reflected in the glass. The wall is cream-colored, and the sky is clear blue. His shadow is cast on the wall."
37# controlnet_conditioning_scale = 1.0
38
39image = pipe(
40 prompt=prompt,
41 negative_prompt=" ",
42 control_image=control_image,
43 controlnet_conditioning_scale=controlnet_conditioning_scale,
44 width=control_image.size[0],
45 height=control_image.size[1],
46 num_inference_steps=30,
47 true_cfg_scale=4.0,
48 generator=torch.Generator(device="cuda").manual_seed(42),
49).images[0]
50image.save(f"qwenimage_cn_union_result.png")