text-to-image-SDXL / Working_TTI_CPU.py
kasper-boy's picture
Create Working_TTI_CPU.py
b74bad5 verified
raw
history blame contribute delete
518 Bytes
from diffusers import DiffusionPipeline
import torch
from PIL import Image
# Load the model
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float32, # Use float32 for CPU
use_safetensors=True
)
pipe.to("cpu")
# Define the prompt
prompt = "An astronaut riding a green horse"
# Generate the image
result = pipe(prompt=prompt)
image = result.images[0]
# Save the image
image.save("generated_image.png")
print("Image saved as generated_image.png")