services:
  tts-server:
    container_name: singlish-tts-server
    stdin_open: true
    build:
      context: tts
      dockerfile: Dockerfile    
      args:
        CUDA_VERSION: 12.2.0
        PYTHON_VERSION: "3.10"
    image: klnxrepo01.klass.dev/speech-milipol-2026/singlish-tts-server:${TAG}
    env_file: [".env"]
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
    gpus: all
    volumes:
      # - /hpc-datasets-ceph/ml_weights_cache/.cache:/root/.cache
      - ${TTS_LOG_DIR}:/app/logs
      - ${TTS_OUTPUT_DIR}:/app/outputs
      - ${PWD}/tts/src:/app/src
      - ${PWD}/tts/ref:/app/ref
      - ${COSYVOICE_MODEL_DIR}:/app/model
    ports:
      - "8200:8200"
    entrypoint: ["python", "-u", "src/main.py"]
    networks:
      - speech_milipol_network

  stt-server:
    build:
      context: .
      dockerfile: whisper-streamer/build/Dockerfile
    image: klnxrepo01.klass.dev/speech-milipol-2026/stt-server:${TAG}
    container_name: stt-server
    volumes:
      -  "~/git/stockholm/klass-version/speech-for-milipol-2026/whisper-streamer/src/whisper_server.py:/opt/whisper_server.py"
      -  "~/git/stockholm/klass-version/speech-for-milipol-2026/whisper-streamer/src/whisper_gstreamer.py:/opt/whisper_gstreamer.py"
      -  "~/git/stockholm/klass-version/speech-for-milipol-2026/whisper-streamer/src/whisper_online.py:/opt/whisper_online.py"
      -  "~/git/stockholm/klass-version/speech-for-milipol-2026/whisper-streamer/src/eng_short.wav:/opt/eng_short.wav"
      -  ~/git/stockholm/klass-version/speech-for-milipol-2026/whisper-streamer/exp:/opt/exp
      - "${faster_whisper_model_path}:/opt/app/faster_whisper"
      - "${COMMAND_FILE_PATH}:/opt/command.json"
      # - "${whisper_models_path}:/opt/app/whisper"
    ports:
      - "8300:8300"
    hostname: whisper-streamer-server
    entrypoint: ["python", "-u", "/opt/whisper_server.py"]
    healthcheck:
      test: curl --insecure http://localhost:8300 || exit 1
      interval: 60s
      timeout: 3s
      retries: 3
      start_period: 3s
    runtime : nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - WHISPER_SERVER_PORT=${whisper_server_port}
      - MAX_WORKER_COUNT=${max_worker_count}
    networks:
      - speech_milipol_network
  
  kognitive-ui:
    image: klnxrepo01.klass.dev/devops/node:20.15.0-alpine
    restart: always
    container_name: kognitive-ui
    command: sh -c "apk --no-cache add git openssh-client graphviz docker-cli;git config --global --add safe.directory /app;cd /app;npm install && npm run dev"
    environment:
      - BASE_PATH=/ui
    volumes:
      - ./ui/.:/app
    networks:
      - speech_milipol_network

  nginx:
    image: klnxrepo01.klass.dev/library/nginx:1.27.0-alpine-slim
    volumes:
      - ./ui/localhost-access-nginx.conf:/etc/nginx/conf.d/default.conf
    command: nginx -g "daemon off;"
    healthcheck:
      test: curl -f http://localhost
    ports:
      - '80:80'
    depends_on:
      kognitive-ui:
        condition: service_started
      stt-server:
        condition: service_healthy
    networks:
      - speech_milipol_network

networks:
  speech_milipol_network:
    name: speech_milipol_network