Who it is forA developer adding image generation to a script, app or notebook.
The problemWiring up a diffusion model by hand means dealing with tokenizers, schedulers and model weights separately.
The outcomeGenerated images from any of thousands of Hub checkpoints using one pipeline object.
What you need first
- Python in a virtual environment
- PyTorch; install with `pip install --upgrade diffusers[torch]` or conda
- An NVIDIA GPU for the README examples, which call to cuda; Apple Silicon has its own guide
Steps
- Install with
pip install --upgrade diffusers[torch] - Load a pipeline:
DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16) - Move it to the GPU with pipeline.to("cuda")
- Call the pipeline with a prompt such as An image of a squirrel in Picasso style and take images[0]
- Browse the Hub for other checkpoints and swap the model id
Prompt for your agent
Using huggingface/diffusers, write a script that loads <model id> with DiffusionPipeline in float16 on CUDA, generates 4 images for <prompt> with fixed seeds, and saves them as PNG files in <folder>.
Caveat. Check each model's license on the Hub before using its images commercially; some checkpoints restrict use.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for huggingface/diffusers and "Generate images from text in a few lines of Python"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer