21 lines
573 B
Python
21 lines
573 B
Python
|
|
import torch
|
|
from diffusers import StableDiffusionPipeline
|
|
from PIL import Image
|
|
|
|
# Load the model from the local file
|
|
model_path = "sdxlAni.safetensors"
|
|
pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16)
|
|
|
|
# Move the pipeline to GPU if available
|
|
if torch.cuda.is_available():
|
|
pipe = pipe.to("cuda")
|
|
|
|
# Generate an image
|
|
prompt = "A fantasy landscape with mountains and a river"
|
|
image = pipe(prompt).images[0]
|
|
|
|
# Save the generated image
|
|
image.save("generated_image.png")
|
|
|
|
print("Image generated and saved as 'generated_image.png'")
|