Skip to content

Instantly share code, notes, and snippets.

@vhata
Last active July 29, 2023 21:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vhata/682875511379c036878271d76bfc78ed to your computer and use it in GitHub Desktop.
Save vhata/682875511379c036878271d76bfc78ed to your computer and use it in GitHub Desktop.

This assumes you have homebrew installed from https://brew.sh/ but if you have a Rust compiler and a Python 3 installation, you don't need it.

brew install rust python@3.10  # if you don't already have these

python3 -m venv stablediff
source stablediff/bin/activate

pip install --upgrade pip setuptools wheel
pip install ipython
pip install diffusers==0.2.4
pip install "ipywidgets>=7,<8"
pip install transformers scipy ftfy

Run huggingface-cli login

Run ipython and then:

import time
import torch
from IPython.display import Image
from diffusers import StableDiffusionPipeline
  
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=True)

def generate_image(prompt, num_steps=50):
    seed = torch.manual_seed(time.time())
    images = pipe([prompt], num_inference_steps=num_steps, guidance_scale=7.5, generator=seed)["sample"]
    return images[0]

image = generate_image("Dogs playing poker")
image.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment