hf-image-api / docker-compose.yml
kajalan's picture
Upload 17 files (#8)
576a898
Raw History Blame Contribute Delete
2.69 kB
services:
hf-image-api:
build:
context: .
dockerfile: Dockerfile
target: final
image: hf-image-api:latest
container_name: hf-image-api
ports:
- "8000:7860"
# ── Persistent volumes ─────────────────────────────────────────────────────
volumes:
# Model weights persist between container restarts (avoids re-downloading)
- model_cache:/app/model_cache
# Generated images persist and are accessible on the host
- ./outputs:/app/outputs
# ── Environment (edit here or in .env) ────────────────────────────────────
environment:
# Get your free token at https://huggingface.co/settings/tokens
# Enables higher rate limits and faster file resolution from HuggingFace
HF_TOKEN: ${HF_TOKEN:-}
MODEL_ID: ${MODEL_ID:-nota-ai/bk-sdm-small}
AUTO_LOAD_MODEL: ${AUTO_LOAD_MODEL:-true}
CPU_THREADS: ${CPU_THREADS:-0}
ENABLE_ATTENTION_SLICING: ${ENABLE_ATTENTION_SLICING:-true}
DEFAULT_STEPS: ${DEFAULT_STEPS:-20}
MAX_STEPS: ${MAX_STEPS:-50}
DEFAULT_WIDTH: ${DEFAULT_WIDTH:-512}
DEFAULT_HEIGHT: ${DEFAULT_HEIGHT:-512}
MAX_WIDTH: ${MAX_WIDTH:-768}
MAX_HEIGHT: ${MAX_HEIGHT:-768}
DEFAULT_GUIDANCE_SCALE: ${DEFAULT_GUIDANCE_SCALE:-7.5}
OUTPUTS_DIR: /app/outputs
MODEL_CACHE_DIR: /app/model_cache
# ── CPU resource limits ────────────────────────────────────────────────────
# Remove or adjust based on your machine
deploy:
resources:
limits:
cpus: "4.0" # cap at 4 cores (set to your core count)
memory: 8G # 8 GB for bk-sdm-small; use 12 GB for SD v1.5
reservations:
memory: 2G
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7860/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 90s # give extra time for model download on first run
# ── Named volumes ──────────────────────────────────────────────────────────────
volumes:
model_cache:
driver: local