FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04

ARG XVC_COMMIT=49df8c591eafc48b096e466d96f9839f9c0dd739

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
      ca-certificates curl ffmpeg git libsndfile1 python3 python3-pip python3-venv \
    && rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/Jerrister/X-VC.git /opt/xvc \
    && cd /opt/xvc \
    && git checkout "${XVC_COMMIT}" \
    && rm -rf .git

RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:${PATH}"

# RTX 5080: use a CUDA 12.8 PyTorch build instead of X-VC's older training pin.
RUN python -m pip install --no-cache-dir --upgrade pip \
    && python -m pip install --no-cache-dir \
      --index-url https://download.pytorch.org/whl/cu128 \
      "torch==2.8.0" "torchaudio==2.8.0" \
    && python -m pip install --no-cache-dir \
      "gradio>=5.49,<6" "huggingface_hub>=0.34,<2" \
      "transformers>=4.44,<5" "hydra-core>=1.3,<2" "omegaconf>=2.3,<3" \
      "x-transformers>=1.40,<3" "einops>=0.8,<1" "einx>=0.3,<1" \
      "numpy>=1.26,<3" "scipy>=1.13,<2" "soundfile>=0.12,<1" \
      "soxr>=0.5,<1" "tqdm>=4.66,<5" "wandb>=0.18,<1"

RUN python -m pip install --no-cache-dir "descript-audiotools==0.7.2"

COPY app.py /opt/xvc/local_webui.py
COPY inference_log.py /opt/xvc/utils/log.py

ENV HF_HOME=/models/huggingface \
    PYTHONUNBUFFERED=1

EXPOSE 8009

HEALTHCHECK --interval=5s --timeout=3s --start-period=600s --retries=3 \
  CMD curl -fsS http://127.0.0.1:8009/ >/dev/null || exit 1

CMD ["python", "/opt/xvc/local_webui.py"]
