Views
No views yet
1import PIL
2import requests
3import torch
4from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
5
6model_id = "timbrooks/instruct-pix2pix"
7pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
8pipe.load_lora_weights("SherryXTChen/InstructCLIP-InstructPix2Pix")
9pipe.to("cuda")
10pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
11
12url = "https://raw.githubusercontent.com/SherryXTChen/Instruct-CLIP/refs/heads/main/assets/1_input.jpg"
13def download_image(url):
14 image = PIL.Image.open(requests.get(url, stream=True).raw)
15 image = PIL.ImageOps.exif_transpose(image)
16 image = image.convert("RGB")
17 return image
18image = download_image(url)
19
20prompt = "as a 3 d sculpture"
21images = pipe(prompt, image=image, num_inference_steps=20).images
22images[0].save("output.jpg")