#!/bin/bash
set -e

echo "=== [1/4] Installing System dependencies (FFmpeg & OpenCV libs) ==="
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y ffmpeg libsm6 libxext6 wget git

echo "=== [2/4] Installing Python requirements ==="
pip install --no-cache-dir gdown opencv-python-headless tensorrt tqdm

echo "=== [3/4] Compiling Unified PureVision + SPAN TensorRT FP16 Engine ==="
python /workspace/build_engine.py /workspace/purescale_4k_end2end.onnx /workspace/purescale_4k.engine

echo "=== [4/4] Starting TensorRT 4K Batch Upscaler for EP3-EP8 in background ==="
nohup python -u /workspace/trt_pipeline.py > /workspace/trt_run.log 2>&1 &
echo "✓ Pipeline launched! PID: $!"
