Created
June 21, 2023 01:16
-
-
Save varunshenoy/894c7a723de6b4651380dd7fa2a81724 to your computer and use it in GitHub Desktop.
An extension for Opendream that adds Instruct Pix2Pix as an operation. Read more here: https://github.com/timothybrooks/instruct-pix2pix.
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
import torch | |
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler | |
from opendream import opendream | |
from opendream.layer import Layer, ImageLayer | |
@opendream.define_op | |
def instruct_pix2pix(image_layer: ImageLayer, prompt, device = "mps"): | |
model_id = "timbrooks/instruct-pix2pix" | |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float32, safety_checker=None) | |
pipe.to(device) | |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config) | |
images = pipe(prompt, image=image_layer.get_image().convert("RGB"), num_inference_steps=10, image_guidance_scale=1).images | |
return Layer(images[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment