How rupeshs/fastsdcpu works
Project type and purpose
• FastSD CPU is a multi-interface image-generation engine built on Stable Diffusion, optimized for CPU (via OpenVINO), LoRA, ControlNet, and GGUF (stablediffusion.cpp) workflows.
• It provides three user interfaces (Desktop Qt GUI, Web UI, CLI) plus a REST/MCP API, and supports specialized pipelines (LCM, LCM-LoRA, OpenVINO, GGUF).
File structure
• Top-level “src” directory splits into “frontend” and “backend” packages.
• “src/app.py” is the entry point; it launches UIs or API/MCP servers.
• “src/backend” contains annotators (ControlNet), model-loading, pipeline implementations, device abstraction, and image-saving utilities.
• “src/frontend” holds CLI, Qt GUI, and WebUI modules.
• “configs” and “models” directories store model lists and downloaded model files (OpenVINO, LCM, LoRA, GGUF).
• Scripts like “start-webui.sh”, “start-mcpserver.sh” orchestrate different run modes.
README insights
• Multiple interfaces: Desktop GUI (Qt), WebUI (FastAPI + uvicorn), CLI, MCP server (Model Context Protocol).
• Pipelines: LCM, LCM-LoRA, OpenVINO int8, ControlNet annotators, GGUF via stablediffusion.cpp.
• Device support: CPU, GPU, NPU (via OpenVINO), MPS (mac), or external shared library for GGUF.
Main components & interactions
a. Frontend tier
• Desktop GUI (Qt widgets)
• Web UI (HTTP server + HTML/JS UI)
• CLI (interactive command line)
• External clients via MCP or REST API (Claude desktop, OpenWebUI)
b. API/Gateway layer
• app.py uses FastAPI or MCP server modules to expose endpoints (/api/generate, /mcp)
• CLI and GUI invoke the same core services through function calls
c. Core backend
• Controller: route input → correct pipeline
• Pipelines: LCM, LCM-LoRA, OpenVINO pipelines, GGUF pipeline
• Annotators: ControlNet pre- and post-processing modules
• Model loader: reads configs, loads models from “models/…” or “lora_models”/“controlnet_models”
• Device abstraction: selects CPU/GPU/NPU/MPS or stablediffusion.cpp shared library
• Image saver / encoder: stores disk files & encodes base64 to return via API
d. File system & config
• configs/*.txt: model lists
• models/…: downloaded model binaries (OpenVINO IR, safetensors, .gguf)
e. External services / dependencies
• OpenVINO toolkit
• stablediffusion.cpp shared library for GGUF
• Python dependencies (FastAPI, PyQt, uv)
Architectural patterns & principles
• Layered architecture: UI → API → core services → pipelines → device & model loader
• Plugin-style pipelines and annotators: each pipeline and annotator module implements a common interface for interchangeability
• Separation of concerns: distinct modules for UI, API, model handling, and device abstraction
• Configuration-driven: behavior determined by “configs” files and environment variables (DEVICE)
Details
• That both CLI and Desktop GUI call into the same core app.py rather than separate code paths.
• Multi-pipeline support and annotator extensions as plugin modules under the “Backend Engine”.
• Device-selection logic (CPU vs. OpenVINO vs. GGUF shared lib).
• Configs directory feeding into the Model Loader.