Production-ready CLI and Web UI for Stable Diffusion with advanced YAML templating system
Features β’ Quick Start β’ Documentation β’ Contributing
Born from frustration with the Stable Diffusion cargo cult.
When you start with Stable Diffusion, you inevitably copy-paste "magic prompts" from Reddit, Discord, or CivitAI. You tweak seeds randomly. You manually generate hundreds of images, changing one parameter at a time. You lose track of what settings produced which results. You can't reproduce your best outputs.
This is cargo cult prompt engineeringβand it doesn't scale.
This CLI was built to escape that chaos. It transforms SD workflows into systematic, reproducible, version-controlled processes:
- Template inheritance instead of copy-pasting prompts
- Combinatorial testing instead of manual parameter tweaking
- Manifests and metadata instead of lost settings
- Reusable chunks instead of monolithic prompts
- Random sampling for exploring large variation spaces efficiently
Perfect for:
- LoRA training datasets - Generate comprehensive character/style variations systematically
- Prompt research - Test hypotheses with controlled experiments, not guesswork
- Batch generation - Hundreds of images with traceable parameters
- Production workflows - Reproducible pipelines you can commit to git
- Inheritance - Multi-level template inheritance with
implements: - Modular imports - Reusable prompt chunks with
imports: - Advanced selectors -
[random:N],[limit:N],[indexes:1,5,8],[keys:foo,bar],[#start-end] - Weight-based loops - Control iteration order with
weight:for optimal combinations - Type-safe - Full mypy strict type checking for reliability
- Combinatorial - Generate all possible combinations (exhaustive testing)
- Random - Smart sampling for large variation spaces
- Seed control - Fixed, progressive, or random seeds per image
- Real-time annotations - Automatic metadata injection with thread-safe queue
- Session management - Organized output with manifests and metadata
- Dry-run mode - Preview API payloads without generating
- API introspection - List available models, samplers, schedulers, upscalers
- Error recovery - Robust error handling and validation
- Vue.js frontend - Clean, responsive interface
- FastAPI backend - High-performance API with async support
- GUID-based auth - Simple token authentication
- Dev mode - Hot reload for rapid development
- Python 3.10+
- Stable Diffusion WebUI (Automatic1111) running with
--apiflag
# Clone the repository
git clone https://github.com/oinant/local-sd-generator.git
cd local-sd-generator
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install CLI package (development mode)
cd packages/sd-generator-cli
pip install -e .# Initialize configuration (creates sdgen_config.json in current directory)
sdgen init
# Edit config to point to your SD WebUI
# Default: http://127.0.0.1:7860
# Generate from a template
sdgen generate -t path/to/your/template.yaml
# Or use interactive mode to select from available templates
sdgen generateCreate my-first-template.prompt.yaml:
name: "Character Variations"
version: 2
description: "Generate character with different expressions and poses"
generation:
mode: "random"
max_images: 50
seed:
mode: "progressive"
value: 42
variations:
expression:
- happy
- sad
- surprised
- angry
pose:
- standing
- sitting
- walking
payload:
model: "your-model-name.safetensors"
steps: 30
cfg_scale: 7.5
width: 512
height: 768
prompt:
template: |
masterpiece, best quality,
1girl, {expression} expression, {pose},
detailed face, beautiful lighting
negative_prompt: "low quality, blurry, distorted"Generate:
sdgen generate -t my-first-template.prompt.yaml -n 20This creates 20 random combinations of expressions Γ poses with progressive seeds (42, 43, 44...).
local-sd-generator/
βββ packages/
β βββ sd-generator-cli/ # π― CLI Package
β β βββ sd_generator_cli/
β β β βββ api/ # SD WebUI client
β β β βββ templating/ # Template System V2.0
β β β β βββ loaders/ # YAML parsing
β β β β βββ resolvers/ # Inheritance & imports
β β β β βββ generators/ # Prompt generation
β β β β βββ validators/ # Validation
β β β βββ execution/ # Manifest & executor
β β β βββ cli.py # CLI entry point (Typer)
β β βββ tests/ # Pytest suite
β β
β βββ sd-generator-webui/ # π Web UI Package (Beta)
β βββ backend/ # FastAPI backend
β β βββ sd_generator_webui/
β βββ front/ # Vue.js frontend
β
βββ docs/ # π Documentation
β βββ cli/ # CLI guides & reference
β βββ webapp/ # WebUI documentation
β βββ roadmap/ # Feature planning
β
βββ tools/ # π οΈ Build & quality tools
Design Philosophy:
- Monorepo - CLI and WebUI as separate packages sharing a venv
- Type-safe - Mypy strict mode throughout
- Tested - Comprehensive pytest suite with >80% coverage
- Documented - Single source of truth in
/docs
- Template System V2.0 Architecture
- Inheritance & Imports
- Advanced Selectors
- ADetailer Integration
- Image Annotations
The Web UI provides a modern interface for managing generations and browsing results.
# Install WebUI package
cd packages/sd-generator-webui
pip install -e .
# Install frontend dependencies (dev mode only)
cd front && npm install
# Start in production mode (backend serves frontend)
sdgen webui start
# Or start in dev mode (hot reload)
sdgen webui start --dev-modeVisit http://localhost:8000/webui (production) or http://localhost:5173 (dev).
Generate a GUID for authentication:
# Linux/Mac
uuidgen
# Or use: https://www.uuidgenerator.net/Set environment variables:
export VALID_GUIDS='["your-admin-guid-here"]'
export IMAGE_FOLDERS='[{"path": "/path/to/images", "name": "My Images"}]'Or create a .env file in your working directory (see .env.example).
# Clone and setup venv
git clone https://github.com/oinant/local-sd-generator.git
cd local-sd-generator
python3 -m venv venv
source venv/bin/activate
# Install Poetry
pip install poetry
# Install CLI in dev mode
cd packages/sd-generator-cli
poetry install
pip install -e .
# Install WebUI in dev mode (optional)
cd ../sd-generator-webui
SKIP_FRONTEND_BUILD=1 pip install -e .
cd front && npm install# From CLI package directory
cd packages/sd-generator-cli
# All tests
python3 -m pytest tests/ -v
# With coverage
python3 -m pytest tests/ --cov=sd_generator_cli --cov-report=term-missingUse the build tool for comprehensive checks:
# From project root
python3 tools/build.py
# Or individual checks
python3 -m flake8 packages/sd-generator-cli/sd_generator_cli --max-line-length=120
python3 -m mypy packages/sd-generator-cli/sd_generator_cli --show-error-codes
python3 -m radon cc packages/sd-generator-cli/sd_generator_cli -aContributions are welcome! This project follows a structured development workflow.
-
Check the roadmap - See
docs/roadmap/for planned featureswip/- Currently in progressnext/- Up next (priority 1-6)future/- Backlog (priority 7-10)
-
Pick a task or propose a feature - Open an issue to discuss
-
Development workflow
# Fork and clone git clone https://github.com/YOUR_USERNAME/local-sd-generator.git cd local-sd-generator # Create feature branch git checkout -b feature/your-feature-name # Make changes, add tests # ... # Run quality checks python3 tools/build.py # Commit and push git commit -m "feat: add your feature" git push origin feature/your-feature-name # Open Pull Request
-
Code standards
- Follow PEP 8 (enforced by flake8)
- Add type hints (mypy strict mode)
- Write tests for new features (pytest)
- Keep complexity low (radon CC <10)
- Document in
/docsif adding features
-
PR Guidelines
- Clear description of changes
- Link to related issues
- All tests passing
- Quality checks passing (
tools/build.py) - Update documentation if needed
- Templates - Share interesting template patterns
- Documentation - Tutorials, examples, guides
- Features - Check
docs/roadmap/next/for priorities - Bug fixes - Check open issues
- Tests - Improve coverage
- WebUI - Vue.js frontend improvements
See CODE_REVIEW_GUIDELINES.md for detailed standards.
- Template System V2.0 with inheritance & imports
- Advanced selectors with weight-based loops
- Real-time image annotations
- Combinatorial & random generation modes
- Comprehensive test suite
- WebUI beta
- Check
docs/roadmap/wip/
- PyPI package publication
- Extended API introspection
- Batch template validation
- Enhanced error reporting
- Template marketplace
Full roadmap: docs/roadmap/
This project is licensed under the MIT License - see the LICENSE file for details.
- Stable Diffusion WebUI (Automatic1111) - The foundation
- Poetry - Python packaging
- Typer - Beautiful CLIs
- FastAPI - Modern web framework
- Vue.js - Progressive JavaScript framework
Made with β€οΈ for the Stable Diffusion community
β Star this repo if you find it useful!