#!/bin/bash
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive

echo "=== Neucodec worker onstart ==="

apt-get update -qq && apt-get install -y -qq libsndfile1 > /dev/null 2>&1

pip install --quiet neucodec boto3 psycopg2-binary pandas pyarrow soundfile 2>&1 | tail -3

# Pre-download model weights
python3 -c "from neucodec import NeuCodec; NeuCodec.from_pretrained('neuphonic/neucodec')" 2>/dev/null

# Write worker.py
cat > /workspace/worker.py << 'WORKER_EOF'
WORKER_EOF

# Write .env
cat > /workspace/.env << 'ENV_EOF'
ENV_EOF

cd /workspace
set -a && source .env && set +a

echo "=== Starting worker ==="
python3 worker.py 2>&1 | tee /workspace/worker.log
