hf-image-api / README.md
kajalan's picture
Upload 17 files (#8)
576a898
|
Raw History Blame Contribute Delete
1.65 kB
metadata
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)