stable-diffusion/text-to-image.py

17 lines
462 B
Python
Raw Normal View History

2023-11-08 17:50:10 +00:00
import torch
from diffusers import StableDiffusionXLPipeline
pipe = StableDiffusionXLPipeline.from_pretrained(
'stabilityai/stable-diffusion-xl-base-1.0',
torch_dtype=torch.float16,
use_safetensors=True,
variant='fp16')
pipe.to('cuda')
def generate_image(prompt: str):
return pipe(prompt=prompt, num_inference_steps=20).images[0]
image = generate_image('cthulhu, paper craft art, minimal detail')
image.show()
# image.save('image.png')