Skip to content

Instantly share code, notes, and snippets.

@offchan42
Last active March 25, 2023 06:13
Show Gist options
  • Save offchan42/e0b4169000fdbaf018d96bdcc05ae1c9 to your computer and use it in GitHub Desktop.
Save offchan42/e0b4169000fdbaf018d96bdcc05ae1c9 to your computer and use it in GitHub Desktop.
Load stable diffusion pipeline with model cache in google drive. Use in Colab
cache_dir = "/root/.cache/huggingface/hub"
!ln -fs /content/drive/MyDrive/huggingface_hub_cache $cache_dir
from diffusers import StableDiffusionPipeline
import torch
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, cache_dir=cache_dir, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]
image.save("astronaut_rides_horse.png")
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment