@echo off
setlocal
cd /d "%~dp0"

if not exist ".venv\Scripts\python.exe" (
    echo [AI][ERROR] .venv not found. Please run setup_ai_env.bat first.
    pause
    exit /b 1
)

if not exist "models\faster-whisper-base" (
    echo [AI][ERROR] Missing local ASR model: models\faster-whisper-base
    echo [AI][FIX] Run download_customer_demo_models.bat once on a networked PC.
    pause
    exit /b 1
)

if not exist "models\opus-mt-en-zh" (
    echo [AI][ERROR] Missing local translator model: models\opus-mt-en-zh
    echo [AI][FIX] Run download_customer_demo_models.bat once on a networked PC.
    pause
    exit /b 1
)

set HF_HOME=%CD%\.cache\huggingface
set HUGGINGFACE_HUB_CACHE=%CD%\.cache\huggingface\hub
set HF_HUB_OFFLINE=1
set TRANSFORMERS_OFFLINE=1

echo [AI] Starting HWS customer demo service...
echo [AI] One service supports both YOLO Objects and ASR EN-^>CN.
echo [AI] Startup uses local models only. No online download during demo startup.
echo [AI] HTTP:      http://127.0.0.1:8765
echo [AI] WebSocket: ws://127.0.0.1:8766/v1/ai/stream

.venv\Scripts\python.exe local_ai_service.py ^
    --host 127.0.0.1 ^
    --port 8765 ^
    --ws ^
    --ws-port 8766 ^
    --model yolo11n.pt ^
    --events ^
    --conf 0.35 ^
    --asr ^
    --asr-model models\faster-whisper-base ^
    --asr-local-only ^
    --asr-device cpu ^
    --asr-compute-type int8 ^
    --asr-language en ^
    --asr-task transcribe ^
    --asr-window-seconds 3.0 ^
    --translate ^
    --dst-lang zh ^
    --translator hf ^
    --translator-model models\opus-mt-en-zh ^
    --translator-local-only ^
    --translator-required

pause
