|
from diffusers import StableDiffusionImg2ImgPipeline |
|
import torch |
|
from PIL import Image |
|
|
|
|
|
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16) |
|
pipe = pipe.to("cuda") # Use "cuda" if you have a GPU; otherwise, use "cpu" |
|
|
|
|
|
init_image = Image.open("path/to/your/image.jpg").convert("RGB") |
|
|
|
|
|
prompt = "A futuristic cityscape at sunset, with neon lights and high-tech buildings" |
|
|
|
|
|
output = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5) |
|
|
|
|
|
output.images[0].save("path/to/save/transformed_image.jpg") |