# Stable Audio Open 1.0 — Stability AI's open-weight latent-diffusion
# SFX/ambience generator. 1.21B params, ~4-6 GB VRAM in fp16, up to
# 47 s clips at 44.1 kHz. Strong on text-aligned sound effects, foley,
# field-recording-style ambience. NOT a music model — it does not
# generate intelligible vocals or structured songs (use ACE-Step for
# that).
#
# LICENSE: Stability AI Community License. Personal / research use is
# free; commercial use requires a separate license from Stability
# (https://stability.ai/license). Same posture we already accepted
# for Voxtral.
#
# No upstream Docker image — we ship a custom Dockerfile + a small
# FastAPI shim (server.py) that wraps diffusers' StableAudioPipeline
# and exposes POST /v1/audio/sfx.
#
# All tunables live in .env — edit that, not this file.

services:
  stable-audio-open:
    image: local/stable-audio-open:${SAO_TAG}
    build:
      # Build context is the compose dir on the host — the playbook
      # uploads server.py + Dockerfile alongside this compose.yaml.
      context: .
      dockerfile: Dockerfile
    container_name: stable-audio-open
    restart: unless-stopped
    runtime: nvidia
    ports:
      - "${SAO_BIND:-0.0.0.0}:${SAO_PORT}:8000"
    environment:
      - NVIDIA_VISIBLE_DEVICES=${SAO_GPU_DEVICES:-1}
      - SAO_MODEL=${SAO_MODEL:-stabilityai/stable-audio-open-1.0}
      - HF_HOME=/app/hf_cache
      # Model is gated on HuggingFace (you must accept the Stability
      # Community License once on the model page before the token can
      # download it). Set SAO_HF_TOKEN in .env. Without this, the
      # first model download 401s and the container crashloops.
      - HF_TOKEN=${SAO_HF_TOKEN}
    volumes:
      - ${SAO_CACHE_DIR}:/app/hf_cache
      - ${SAO_OUTPUTS_DIR}:/app/outputs
    healthcheck:
      # /health is set by server.py — returns 200 once FastAPI is up
      # AND the pipeline finished loading (lifespan blocks startup
      # until the model is in VRAM).
      test: ["CMD-SHELL", "python -c \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=5).status==200 else 1)\""]
      interval: 30s
      timeout: 10s
      retries: 3
      # First boot pulls the model (~6 GB) into HF cache + loads to
      # VRAM. Cold start ~3-5 min on a fast pipe; subsequent starts
      # are ~30 s.
      start_period: 600s
    labels:
      - homepage.group=AI Systems
      - homepage.name=Stable Audio Open
      - homepage.icon=mdi-waveform
      - homepage.description=Diffusion SFX/ambience generator — up to 47s at 44.1 kHz (irv-ml1)
      - homepage.href=http://10.100.79.3:${SAO_PORT}
