Update README.md
Browse files5 unmodified lines67891011121314151617181920212223242526272829303132333435363738394041424344455 unmodified lines```pythonimport torchfrom diffusers.modular_pipelines import ModularPipelineBlocks, SequentialPipelineBlocksfrom diffusers.modular_pipelines.stable_diffusion_xl import TEXT2IMAGE_BLOCKS, CONTROLNET_BLOCKSfrom diffusers.utils import load_image# fetch the depth processor block that will create our depth mapdepth_processor_block = ModularPipelineBlocks.from_pretrained("diffusers/depth-processor-custom-block", trust_remote_code=true)my_blocks = TEXT2IMAGE_BLOCKS.copy()my_blocks.insert("depth_processor", depth_processor_block, 1)# replace text to image denoise block with controlnet denoise blockmy_blocks.sub_blocks["denoise"] = CONTROLNET_BLOCKS["denoise"]# create our initial set of controlnet blocksblocks = SequentialPipelineBlocks.from_blocks_dict(my_blocks)repo_id = "diffusers/modular-stable-diffusion-xl-base-1.0"# Initialize the pipeline object we can use to run our blockspipe = blocks.init_pipeline(repo_id)# Load model component weightspipe.load_components(torch_dtype=torch.float16, device_map="cuda")image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true")image = image.resize((1024, 1024))prompt = ["A red car"]output = pipe(prompt=prompt,image=image,num_inference_steps=35,guidance_scale=7.5,output_type="pil",)```5 unmodified lines678910111213141516171819202122232425262728293031323334353637383940414243444546475 unmodified lines```pythonimport torchfrom diffusers import ModularPipeline, ComponentsManager, ModularPipelineBlocksfrom diffusers.utils import load_image# Use ComponentsManager to enable auto CPU offloading for memory efficiencymanager = ComponentsManager()manager.enable_auto_cpu_offload(device="cuda:0")# Initialize pipelinepipe = ModularPipeline.from_pretrained("Qwen/Qwen-Image", components_manager=manager)# Insert a depth processing blockblocks = pipe.blocks.get_workflow("controlnet_text2image")depth_block = ModularPipelineBlocks.from_pretrained("diffusers/depth-processor-custom-block",trust_remote_code=True,)blocks.sub_blocks.insert("depth", depth_block, 0)# Reinitialize the pipeline for ControlNetpipe = blocks.init_pipeline("Qwen/Qwen-Image", components_manager=manager)pipe.load_components(torch_dtype=torch.bfloat16)# Load the ControlNet modelcontrolnet_spec = pipeline.get_component_spec("controlnet")controlnet_spec.pretrained_model_name_or_path = "InstantX/Qwen-Image-ControlNet-Union"controlnet = controlnet_spec.load(torch_dtype=torch.bfloat16)pipeline.update_components(controlnet=controlnet)# Inferprompt = "cat wizard with red hat, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney"image = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/cute_cat.png?raw=true")output = pipeline(prompt=prompt,image=image,).images[0]output```
README.md+27-25