services:
  speakr:
    image: voice-speakr:runtime
    container_name: voice-speakr
    restart: unless-stopped
    working_dir: /app
    env_file:
      - ./config.env
    environment:
      PYTHONPATH: /app
      SQLALCHEMY_DATABASE_URI: sqlite:////data/instance/transcriptions.db
      UPLOAD_FOLDER: /data/uploads
      USE_ASR_ENDPOINT: "true"
      ASR_BASE_URL: http://asr-test:59805
    volumes:
      - ./speakr:/app
      - ./deploy/data/speakr/uploads:/data/uploads
      - ./deploy/data/speakr/instance:/data/instance
    ports:
      - "8899:8899"
    depends_on:
      - asr-test
      - voice-dected
    command:
      - sh
      - -c
      - >
        mkdir -p /data/uploads /data/instance &&
        python -c "from src.app import app; from src.clients import db; app.app_context().push(); db.create_all()" &&
        exec gunicorn --workers $${GUNICORN_WORKERS:-3} --threads $${GUNICORN_THREADS:-8}
        --bind 0.0.0.0:8899 --timeout $${GUNICORN_TIMEOUT:-600} src.app:app

  voice-dected:
    image: voice-dected:runtime
    container_name: voice-dected
    restart: unless-stopped
    working_dir: /app
    env_file:
      - ./config.env
    environment:
      PYTHONPATH: /app
    volumes:
      - ./voice-dected/src:/app
    ports:
      - "18000:8000"
    command:
      - uvicorn
      - app:app
      - --host
      - 0.0.0.0
      - --port
      - "8000"

  asr-test:
    image: paraformer-asr:latest
    container_name: asr-test
    restart: unless-stopped
    runtime: nvidia
    gpus:
      - driver: nvidia
        device_ids:
          - "7"
        capabilities:
          - gpu
    working_dir: /app
    env_file:
      - ./config.env
    environment:
      DEVICE: cuda
      CUDA_VISIBLE_DEVICES: "0"
      NVIDIA_VISIBLE_DEVICES: "7"
      VOICE_DETECTED_URL: http://voice-dected:8000
      VOICEPRINT_STORE: /data/asr_voiceprints.json
    volumes:
      - ./asr/main.py:/app/main.py:ro
      - /storage01/home/xll/audio:/app/audio:ro
      - /storage01/home/xll/weixiu-hj/seacomodel:/app/models/seacomodel:ro
      - /storage01/home/xll/weixiu-hj/vadmodel:/app/models/vadmodel:ro
      - /storage01/home/xll/weixiu-hj/ctpuncmodel:/app/models/ctpuncmodel:ro
      - /storage01/home/xll/weixiu-hj/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/example/hotword.txt:/app/hotword.txt:ro
      - ./deploy/data/asr:/data
    ports:
      - "59805:59805"
    depends_on:
      - voice-dected
    command:
      - uvicorn
      - main:app
      - --host
      - 0.0.0.0
      - --port
      - "59805"
      - --workers
      - "1"

  fastapi-wss:
    image: fastapi-wss:runtime
    container_name: fastapi-wss
    restart: unless-stopped
    working_dir: /app/src
    env_file:
      - ./config.env
    environment:
      TARGET_WS_URL: ws://asr-test:59805/ws/asr
      REDIS_URL: redis://redis:6379/0
    volumes:
      - ./fastapi_wss:/app
    ports:
      - "10095:10095"
    depends_on:
      - asr-test
      - redis
    command:
      - python
      - a2a_wss.py

  redis:
    image: redis:7-alpine
    container_name: voice-redis
    restart: unless-stopped
    volumes:
      - ./deploy/data/redis:/data
    ports:
      - "16380:6379"
    command:
      - redis-server
      - --appendonly
      - "yes"
