How to run Hugging Face stable-diffusion on Mac
1 min readMar 22, 2025
This article goes over how to run Hugging Face stable-diffusion AI model on macOS.
Prerequisites
Install Python:
brew install pythonCreate the virtualenv:
python3 -m venv .venvActivate the virtualenv:
source .venv/bin/activateInstall the dependencies:
pip3 install accelerate diffusers torch transformersText-to-Image
Create a script to generate text-to-image:
touch text_to_image.pyImport the diffusers module:
from diffusers import AutoPipelineForText2ImageCreate a pipeline using the dreamlike-art/dreamlike-photoreal-2.0 checkpoint:
model = "dreamlike-art/dreamlike-photoreal-2.0"
pipeline = AutoPipelineForText2Image.from_pretrained(model)Pass the prompt to the pipeline and generate the image:
prompt = "cinematic photo of Godzilla eating sushi with a cat in a izakaya, 35mm photograph, film, professional, 4k, highly detailed"
image = pipeline(prompt).images[0]image.save("my_image.png")Run the script:
python3 text_to_image.pyCode
Here’s the full script:
from diffusers import AutoPipelineForText2Image
model = "dreamlike-art/dreamlike-photoreal-2.0"
pipeline = AutoPipelineForText2Image.from_pretrained(model)
prompt = "cinematic photo of Godzilla eating sushi with a cat in a izakaya, 35mm photograph, film, professional, 4k, highly detailed"
image = pipeline(prompt).images[0]
image.save("my_image.png")See the GitHub demo.
