FROM nvidia/cuda:12.9.0-runtime-ubuntu24.04

# Avoid interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install Python and system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 \
    python3-pip \
    python3-dev \
    git \
    libsndfile1 \
    ffmpeg \
    && rm -rf /var/lib/apt/lists/*

# Set Python alias (Ubuntu 24.04 ships Python 3.12)
RUN ln -sf /usr/bin/python3 /usr/bin/python

# Allow pip to install packages system-wide in the container (PEP 668)
ENV PIP_BREAK_SYSTEM_PACKAGES=1

# Set working directory
WORKDIR /app

# PyTorch (cu128 wheels for CUDA 12.8+/12.9 compat)
RUN pip install --no-cache-dir \
    torch==2.9.0 \
    torchaudio==2.9.0 \
    --index-url https://download.pytorch.org/whl/cu128

# TheStage AI elastic_models (TensorRT engines of TheWhisper); pulls transformers 5.13.1 and TensorRT 10.13.3.9
RUN pip install --no-cache-dir \
    "thestage-elastic-models[nvidia]==0.2.2.post0" \
    --extra-index-url https://thestage.jfrog.io/artifactory/api/pypi/pypi-thestage-ai-production/simple \
    --extra-index-url https://pypi.nvidia.com

# Common requirements
RUN pip install --no-cache-dir \
    evaluate \
    datasets==3.6.0 \
    librosa \
    soundfile \
    jiwer \
    num2words \
    kaldialign \
    voi_oiwer

# Copy the full repository
COPY . /app

# Default entrypoint
ENTRYPOINT ["bash"]

# Keep-alive CMD so the Space runtime stays healthy. HF Jobs and `docker run`
# override this with their own command.
EXPOSE 7860
CMD ["-c", "python3 -m http.server 7860"]
