--- title: HF Image API emoji: 🖼️ colorFrom: blue colorTo: purple sdk: docker pinned: false app_port: 7860 --- # HF CPU Image Generation API A job-queue REST API for Stable Diffusion image generation on CPU using Hugging Face Diffusers. **Swagger UI:** `https://your-space-url.hf.space/docs` ## Job flow ``` POST /generate → { job_id, status: "queued" } GET /jobs/{id} → { status: "processing", progress: 45 } GET /jobs/{id} → { status: "completed", download_url: "..." } GET /jobs/{id}/download → image.png DELETE /jobs/{id} → removes job + image ``` ## API endpoints | Method | Path | Description | |---|---|---| | `POST` | `/generate` | Submit a generation job | | `GET` | `/jobs` | List all jobs | | `GET` | `/jobs/{id}` | Poll job status & progress | | `GET` | `/jobs/{id}/download` | Download the PNG | | `DELETE` | `/jobs/{id}` | Delete job + image | | `GET` | `/health` | Pipeline & queue status | | `GET` | `/models` | List supported models | | `POST` | `/models/load` | Hot-swap model | ## CPU optimisations - `torch.float32` (mandatory for CPU) - `DPMSolverMultistepScheduler` — converges at 20 steps - `enable_attention_slicing` — lower peak RAM - `low_cpu_mem_usage=True` — no double-buffering - `safety_checker=None` — saves ~300 MB RAM ## Default model `nota-ai/bk-sdm-small` (~500 MB) — fastest on CPU, ~60–120s per 512×512 image. ## HF Spaces Secrets Set these under **Settings → Secrets** in your Space: | Secret | Description | |---|---| | `HF_TOKEN` | Your HuggingFace token (faster downloads) | | `MODEL_ID` | Override model (e.g. `runwayml/stable-diffusion-v1-5`) |