Production-oriented local image generation app for NVIDIA SANA / SANA Sprint. It runs on your own Windows PC, Linux GPU server, Docker GPU host, or LAN server without paid image APIs and without fake placeholder output.
The app uses the official NVIDIA SANA repository code from https://github.com/NVlabs/Sana and official Hugging Face repositories under https://huggingface.co/Efficient-Large-Model.
- FastAPI backend with clean endpoints:
POST /api/generate,GET /api/history,GET /api/health,GET /outputs/images/{filename}. - Official SANA Sprint 1.6B 1024px checkpoint support.
- Model loads once on server startup and is reused for every request.
- Single generation lock to avoid concurrent GPU crashes.
- Prompt, negative prompt when the installed pipeline supports it, seed, width, height, steps, and guidance scale controls.
- Local image output in
backend/outputs/images/. - Metadata JSON per generation in
backend/outputs/metadata/. - Plain responsive HTML/CSS/JS frontend served at
http://localhost:8000. - Local-only host binding by default.
- NVIDIA GPU strongly recommended.
- CUDA-capable PyTorch installation.
- 8 GB VRAM can work for optimized SANA variants, but 1024px 1.6B generation is safer with more VRAM.
- CPU fallback is disabled by default because SANA Sprint local CPU inference is usually impractical. Enable only for experimentation with
SANA_ALLOW_CPU=true.
image-sana-local/
├── backend/
│ ├── app.py
│ ├── sana_engine.py
│ ├── config.py
│ ├── requirements.txt
│ └── outputs/
│ ├── images/
│ └── metadata/
├── frontend/
│ ├── index.html
│ └── assets/
│ ├── css/style.css
│ └── js/app.js
├── models/
├── scripts/
│ ├── install.sh
│ ├── install.bat
│ ├── run-local.sh
│ ├── run-local.bat
│ └── download-model.py
├── Dockerfile
├── docker-compose.yml
├── README.md
└── .gitignore
Install prerequisites first:
- Git
- Python 3.10 or 3.11
- NVIDIA driver
Run:
cd image-sana-local
scripts\install.batThe installer creates .venv, installs CUDA-enabled PyTorch and torchvision from the official PyTorch CUDA index, installs backend requirements, and clones https://github.com/NVlabs/Sana into Sana\ if missing.
Download the official SANA Sprint model:
python scripts\download-model.pyRun the backend:
cd backend
..\.venv\Scripts\activate
uvicorn app:app --host 0.0.0.0 --port 8000Open:
http://localhost:8000
Use these exact commands for the current project path:
cd D:\7070\image-ai\image-sana-local
scripts\install.bat
python scripts\download-model.py
cd backend
..\.venv\Scripts\activate
uvicorn app:app --host 0.0.0.0 --port 8000If scripts\install.bat reports that Python 3.10 or 3.11 is missing, install Python 3.11 first. Python 3.14 is not recommended for CUDA PyTorch/SANA compatibility.
The frontend calls:
http://localhost:8000/api/generate
Install prerequisites first:
- Git
- Python 3.10 or 3.11
- NVIDIA driver
- CUDA-compatible PyTorch
Run:
cd image-sana-local
bash scripts/install.shIf needed, install CUDA PyTorch inside the virtual environment:
source .venv/bin/activate
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121Download the official SANA Sprint model:
python scripts/download-model.py --model sprint-1.6b-1024Run locally:
bash scripts/run-local.shEquivalent backend command:
cd backend
uvicorn app:app --host 0.0.0.0 --port 8000Use --host 127.0.0.1 for local-only access. The run scripts default to 127.0.0.1.
The install scripts clone the official NVIDIA repository:
git clone https://github.com/NVlabs/Sana.git SanaThe backend validates these files before loading:
Sana/app/sana_sprint_pipeline.pySana/configs/sana_sprint_config/1024ms/SanaSprint_1600M_1024px_allqknorm_bf16_scm_ladd.yamlmodels/Sana_Sprint_1.6B_1024px/Sana_Sprint_1.6B_1024px.pth
Update upstream SANA later with:
cd Sana
git pull origin mainAutomatic download uses official Hugging Face model repositories only:
python scripts/download-model.py --model sprint-1.6b-1024Supported automatic targets:
Efficient-Large-Model/Sana_Sprint_1.6B_1024pxEfficient-Large-Model/SANA1.5_1.6B_1024px_diffusersfor manual future extension, not used by default backend generation
Manual placement is also supported:
models/
├── Sana_Sprint_1.6B_1024px/
│ └── Sana_Sprint_1.6B_1024px.pth
├── Sana_1.5/
└── config/
Environment variables:
| Variable | Default | Purpose |
|---|---|---|
SANA_LOCAL_ONLY |
true |
Bind locally by default. |
SANA_HOST |
127.0.0.1 |
Host for run scripts. Use 0.0.0.0 for LAN. |
SANA_PORT |
8000 |
HTTP port. |
SANA_REPO_DIR |
./Sana |
Official cloned SANA repo. |
SANA_MODEL_DIR |
./models/Sana_Sprint_1.6B_1024px |
Model directory. |
SANA_CONFIG_PATH |
Official Sprint YAML path | SANA Sprint config. |
SANA_ALLOW_CPU |
false |
Allow CPU fallback if you accept very slow inference. |
SANA_MAX_STEPS |
12 |
Request limit for steps. |
SANA_GENERATION_TIMEOUT |
180 |
Request timeout in seconds. |
Health:
curl http://localhost:8000/api/healthGenerate:
curl -X POST http://localhost:8000/api/generate \
-H "Content-Type: application/json" \
-d '{"prompt":"a tiny astronaut hatching from an egg on the moon","width":1024,"height":1024,"steps":2,"guidance_scale":4.5,"seed":42}'History:
curl http://localhost:8000/api/historyGenerated images are returned as URLs like:
/outputs/images/sana-sprint-20260515T120000Z-42-abcd1234.png
Requires NVIDIA Container Toolkit.
Download the model on the host first:
python scripts/download-model.py --model sprint-1.6b-1024Run:
docker compose up --buildOpen:
http://localhost:8000
Local-only is default. To expose on your LAN:
SANA_LOCAL_ONLY=false SANA_HOST=0.0.0.0 bash scripts/run-local.shOnly do this on a trusted network. This app is not configured for public internet exposure, authentication, or TLS.
SANA Sprint in this project uses the official NVIDIA SANA PyTorch implementation. CUDA acceleration requires an NVIDIA GPU. An AMD GPU on Windows is not a CUDA device, so PyTorch will report torch.cuda.is_available() == False.
You can attempt real CPU fallback with:
cd D:\7070\image-ai\image-sana-local
scripts\run-cpu.batCPU fallback is not fake generation, but it can be extremely slow and may require substantial system RAM. AMD GPU acceleration is not enabled by this project because the official SANA repo targets PyTorch CUDA paths, not Windows DirectML.
- Prompt length is limited.
- Negative prompt length is limited.
- Width and height are restricted to
512,768, or1024. - Pixel count and steps are capped.
- Output filenames are generated server-side and sanitized.
- Image serving only allows files from
backend/outputs/images/. - No command execution is exposed through the API.
Check:
python -c "import torch; print(torch.cuda.is_available()); print(torch.version.cuda)"If false, install the CUDA-enabled PyTorch build matching your driver. Example:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121Reduce width/height to 768 or 512, reduce steps, close other GPU applications, and keep only one server worker. The app already serializes generation with a lock and clears CUDA cache after generation when configured.
Run:
python scripts/download-model.py --model sprint-1.6b-1024Then check that this file exists:
models/Sana_Sprint_1.6B_1024px/checkpoints/Sana_Sprint_1.6B_1024px.pth
Run the installer again or clone manually:
git clone https://github.com/NVlabs/Sana.git SanaUse CUDA, keep image size at 1024 or below, keep Sprint steps low, and avoid running multiple uvicorn workers. CPU fallback is not recommended.
Use absolute paths without trailing quotes in environment variables. Example:
set SANA_MODEL_DIR=D:\models\Sana_Sprint_1.6B_1024pxThe backend sends negative_prompt only if the installed official SANA Sprint pipeline exposes that parameter. If the upstream pipeline does not support it, the field is safely ignored.
This project does not use Stable Diffusion, Flux, SDXL, DALL-E, Midjourney, or any external image generation API. Hugging Face is used only for downloading official SANA model files when requested.