imagedemo / .sample
sumau's picture
Create .sample
f51b741 verified
raw
history blame
715 Bytes
from diffusers import StableDiffusionImg2ImgPipeline
import torch
from PIL import Image
# Load the pipeline
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"
# Load the input image
init_image = Image.open("path/to/your/image.jpg").convert("RGB")
# Define the prompt for transformation
prompt = "A futuristic cityscape at sunset, with neon lights and high-tech buildings"
# Run the image-to-image pipeline
output = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5)
# Save the result
output.images[0].save("path/to/save/transformed_image.jpg")