Transformers - stable diffusion example¶
Transformers provides APIs and tools to easily download and train state-of-the-art pretrained models.
Credits: Huggingface documentation and examples
https://github.com/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb
In [ ]:
# install dependencies
!pip install diffusers==0.11.1
!pip install transformers scipy ftfy accelerate
In [2]:
import torch
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
In [3]:
pipe = pipe.to("cuda")
In [4]:
prompt = "a photograph of an astronaut riding a horse"
image = pipe(prompt).images[0] # image here is in [PIL format](https://pillow.readthedocs.io/en/stable/)
In [6]:
# Display the image
image
Out[6]:
In [ ]: