#!/bin/bash
echo "=== BEFORE LOAD ==="
docker ps --format "{{.Names}} {{.Status}}" | sort
echo
echo "=== Loading qwen3-4b ==="
curl -s -X POST http://localhost:9090/api/model/load \
  -H "Content-Type: application/json" \
  -d '{"model_id":"qwen3-4b"}'
echo

# Poll until done
for i in $(seq 1 30); do
  sleep 2
  busy=$(curl -s http://localhost:9090/api/operation/log | python3 -c "import sys,json; print(json.load(sys.stdin)['busy'])")
  if [ "$busy" = "False" ]; then
    echo "=== LOAD COMPLETE ==="
    break
  fi
  echo "  waiting... ($((i*2))s)"
done

echo
echo "=== AFTER LOAD ==="
docker ps --format "{{.Names}} {{.Status}}" | sort
echo
echo "=== OP LOG ==="
curl -s http://localhost:9090/api/operation/log | python3 -c "import sys,json; [print(l) for l in json.load(sys.stdin)['log']]"
echo
echo "=== TTS HEALTH ==="
curl -s http://localhost:8072/health
echo
