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

# NOTE: ABR models use torch.export.load() which has a format incompatibility
# with torch>=2.6. Pin to 2.5.1 (cu124) which matches the version the ABR
# exported models were built with.
RUN pip install --no-cache-dir \
    torch==2.5.1 \
    torchaudio==2.5.1 \
    --index-url https://download.pytorch.org/whl/cu124

# Install common requirements, pinning transformers to a version compatible
# with torch 2.5.1 (torch.float8_e8m0fnu was added in 2.6, newer transformers requires it)
RUN pip install --no-cache-dir \
    "transformers==4.47.1" \
    evaluate \
    "datasets==2.19.0" \
    librosa \
    jiwer \
    num2words \
    peft

# Install ABR-specific dependencies
RUN pip install --no-cache-dir \
    sentencepiece==0.2.1 \
    soundfile

# Force soundfile backend for datasets audio decoding
ENV HF_AUDIO_DECODER_BACKEND=soundfile

# Copy the full repository
COPY . /app

# Default entrypoint
ENTRYPOINT ["bash"]

EXPOSE 7860
CMD ["-c", "python3 -m http.server 7860"]
