File size: 2,694 Bytes
b83bd3c
 
 
 
 
 
 
 
 
 
 
576a898
b83bd3c
 
 
 
 
 
 
 
 
 
47781a1
 
 
b83bd3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576a898
b83bd3c
 
 
 
 
 
 
 
576a898
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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