# =============================================================================
# MiroTalk P2P - Self-hosted Whisper (Speech-to-Text) server
# =============================================================================
#
# Runs an OpenAI-compatible Whisper server so you can use the room
# "Whisper mode" transcription WITHOUT sending audio to the OpenAI API.
#
# The image (ghcr.io/speaches-ai/speaches, formerly fedirz/faster-whisper-server)
# exposes an OpenAI-compatible endpoint at /v1/audio/transcriptions, so MiroTalk
# can talk to it exactly like the official OpenAI API.
#
# -----------------------------------------------------------------------------
# Quick start (CPU, works on any VPS/VDS)
# -----------------------------------------------------------------------------
#   docker compose -f docker-compose-whisper.yml --profile cpu up -d
#
# Quick start (GPU, requires NVIDIA GPU + nvidia-container-toolkit)
#   docker compose -f docker-compose-whisper.yml --profile gpu up -d
#
# -----------------------------------------------------------------------------
# Point MiroTalk P2P at this server
# -----------------------------------------------------------------------------
# In your MiroTalk .env set:
#
#   WHISPER_ENABLED=true
#   # If MiroTalk runs on the SAME host (not in Docker), use localhost:
#   WHISPER_BASE_PATH=http://localhost:8000/v1/
#   # If MiroTalk runs in Docker on the same network, use the service name:
#   # WHISPER_BASE_PATH=http://whisper:8000/v1/
#   # Auth: leave empty for NO AUTH (endpoint is PUBLIC), OR set a secret to require it.
#   # When set, MiroTalk sends it as "Authorization: Bearer <key>" and the
#   # server below must be started with the SAME value (API_KEY env var), so
#   # only MiroTalk can reach it.
#   WHISPER_API_KEY=your-strong-secret-key
#   # IMPORTANT: speaches does NOT auto-download models. The model in WHISPER_MODEL
#   # is preloaded at startup via PRELOAD_MODELS below and selected per request.
#   # Use a REAL model it can load (NOT 'whisper-1' — that is OpenAI-only).
#   WHISPER_MODEL=Systran/faster-whisper-small
#
# =============================================================================

services:
    # -------------------------------------------------------------------------
    # CPU variant — runs anywhere, no GPU required.
    # -------------------------------------------------------------------------
    whisper:
        image: ghcr.io/speaches-ai/speaches:latest-cpu
        container_name: mirotalkwhisper
        hostname: whisper
        restart: unless-stopped
        profiles: ['cpu']
        ports:
            # Host 8000 -> container 8000 (matches WHISPER default basePath).
            - '${WHISPER_PORT:-8000}:8000'
        environment:
            # speaches does NOT auto-download on request: preload the model at startup.
            # Options: tiny | base | small | medium | large-v3 (Systran/faster-whisper-*)
            PRELOAD_MODELS: '["${WHISPER_MODEL:-Systran/faster-whisper-small}"]'
            WHISPER__INFERENCE_DEVICE: 'cpu'
            # Auth: when set, ALL API requests must send Authorization: Bearer <key>.
            # Use the SAME value as MiroTalk's WHISPER_API_KEY.
            # WARNING: empty = NO AUTH, the endpoint is PUBLIC to anyone who can reach it.
            API_KEY: '${WHISPER_API_KEY:-}'
        volumes:
            - speaches_cache:/home/ubuntu/.cache/huggingface/hub

    # -------------------------------------------------------------------------
    # GPU variant — requires an NVIDIA GPU and nvidia-container-toolkit.
    # -------------------------------------------------------------------------
    whisper-gpu:
        image: ghcr.io/speaches-ai/speaches:latest-cuda
        container_name: mirotalkwhisper
        hostname: whisper
        restart: unless-stopped
        profiles: ['gpu']
        ports:
            - '${WHISPER_PORT:-8000}:8000'
        environment:
            # speaches does NOT auto-download on request: preload the model at startup.
            PRELOAD_MODELS: '["${WHISPER_MODEL:-Systran/faster-whisper-medium}"]'
            WHISPER__INFERENCE_DEVICE: 'cuda'
            # Auth: when set, ALL API requests must send Authorization: Bearer <key>.
            # Use the SAME value as MiroTalk's WHISPER_API_KEY.
            # WARNING: empty = NO AUTH, the endpoint is PUBLIC to anyone who can reach it.
            API_KEY: '${WHISPER_API_KEY:-}'
        volumes:
            - speaches_cache:/home/ubuntu/.cache/huggingface/hub
        deploy:
            resources:
                reservations:
                    devices:
                        - driver: nvidia
                          count: all
                          capabilities: [gpu]

volumes:
    speaches_cache:
