>>> import torch
>>> from diffusers import StableDiffusionGLIGENPipeline
>>> from diffusers.utils import load_image
>>> # Insert objects described by text at the region defined by bounding boxes>>> pipe = StableDiffusionGLIGENPipeline.from_pretrained(
... "masterful/gligen-1-4-inpainting-text-box", variant="fp16", torch_dtype=torch.float16
... )
>>> pipe = pipe.to("cuda")
>>> input_image = load_image(
... "https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/gligen/livingroom_modern.png"... )
>>> prompt = "a birthday cake">>> boxes = [[0.2676, 0.6088, 0.4773, 0.7183]]
>>> phrases = ["a birthday cake"]
>>> images = pipe(
... prompt=prompt,
... gligen_phrases=phrases,
... gligen_inpaint_image=input_image,
... gligen_boxes=boxes,
... gligen_scheduled_sampling_beta=1,
... output_type="pil",
... num_inference_steps=50,
... ).images
>>> images[0].save("./gligen-1-4-inpainting-text-box.jpg")
>>> # Generate an image described by the prompt and>>> # insert objects described by text at the region defined by bounding boxes>>> pipe = StableDiffusionGLIGENPipeline.from_pretrained(
... "masterful/gligen-1-4-generation-text-box", variant="fp16", torch_dtype=torch.float16
... )
>>> pipe = pipe.to("cuda")
>>> prompt = "a waterfall and a modern high speed train running through the tunnel in a beautiful forest with fall foliage">>> boxes = [[0.1387, 0.2051, 0.4277, 0.7090], [0.4980, 0.4355, 0.8516, 0.7266]]
>>> phrases = ["a waterfall", "a modern high speed train running through the tunnel"]
>>> images = pipe(
... prompt=prompt,
... gligen_phrases=phrases,
... gligen_boxes=boxes,
... gligen_scheduled_sampling_beta=1,
... output_type="pil",
... num_inference_steps=50,
... ).images
>>> images[0].save("./gligen-1-4-generation-text-box.jpg")
>>> import torch
>>> from diffusers import StableDiffusionGLIGENTextImagePipeline
>>> from diffusers.utils import load_image
>>> # Insert objects described by image at the region defined by bounding boxes>>> pipe = StableDiffusionGLIGENTextImagePipeline.from_pretrained(
... "anhnct/Gligen_Inpainting_Text_Image", torch_dtype=torch.float16
... )
>>> pipe = pipe.to("cuda")
>>> input_image = load_image(
... "https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/gligen/livingroom_modern.png"... )
>>> prompt = "a backpack">>> boxes = [[0.2676, 0.4088, 0.4773, 0.7183]]
>>> phrases = None>>> gligen_image = load_image(
... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/gligen/backpack.jpeg"... )
>>> images = pipe(
... prompt=prompt,
... gligen_phrases=phrases,
... gligen_inpaint_image=input_image,
... gligen_boxes=boxes,
... gligen_images=[gligen_image],
... gligen_scheduled_sampling_beta=1,
... output_type="pil",
... num_inference_steps=50,
... ).images
>>> images[0].save("./gligen-inpainting-text-image-box.jpg")
>>> # Generate an image described by the prompt and>>> # insert objects described by text and image at the region defined by bounding boxes>>> pipe = StableDiffusionGLIGENTextImagePipeline.from_pretrained(
... "anhnct/Gligen_Text_Image", torch_dtype=torch.float16
... )
>>> pipe = pipe.to("cuda")
>>> prompt = "a flower sitting on the beach">>> boxes = [[0.0, 0.09, 0.53, 0.76]]
>>> phrases = ["flower"]
>>> gligen_image = load_image(
... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/gligen/pexels-pixabay-60597.jpg"... )
>>> images = pipe(
... prompt=prompt,
... gligen_phrases=phrases,
... gligen_images=[gligen_image],
... gligen_boxes=boxes,
... gligen_scheduled_sampling_beta=1,
... output_type="pil",
... num_inference_steps=50,
... ).images
>>> images[0].save("./gligen-generation-text-image-box.jpg")
>>> # Generate an image described by the prompt and>>> # transfer style described by image at the region defined by bounding boxes>>> pipe = StableDiffusionGLIGENTextImagePipeline.from_pretrained(
... "anhnct/Gligen_Text_Image", torch_dtype=torch.float16
... )
>>> pipe = pipe.to("cuda")
>>> prompt = "a dragon flying on the sky">>> boxes = [[0.4, 0.2, 1.0, 0.8], [0.0, 1.0, 0.0, 1.0]] # Set `[0.0, 1.0, 0.0, 1.0]` for the style>>> gligen_image = load_image(
... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/landscape.png"... )
>>> gligen_placeholder = load_image(
... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/landscape.png"... )
>>> images = pipe(
... prompt=prompt,
... gligen_phrases=[
... "dragon",
... "placeholder",
... ], # Can use any text instead of `placeholder` token, because we will use mask here... gligen_images=[
... gligen_placeholder,
... gligen_image,
... ], # Can use any image in gligen_placeholder, because we will use mask here... input_phrases_mask=[1, 0], # Set 0 for the placeholder token... input_images_mask=[0, 1], # Set 0 for the placeholder image... gligen_boxes=boxes,
... gligen_scheduled_sampling_beta=1,
... output_type="pil",
... num_inference_steps=50,
... ).images
>>> images[0].save("./gligen-generation-text-image-box-style-transfer.jpg")