FROM rocm/dev-ubuntu-22.04:6.1.2

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV HF_HOME=/root/.cache/huggingface

# System dependencies
RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip \
    python3-dev \
    espeak-ng \
    libespeak-ng1 \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

# PyTorch 2.5.1 + torchaudio for ROCm 6.1
RUN pip3 install --no-cache-dir \
    torch==2.5.1 \
    torchaudio==2.5.1 \
    --index-url https://download.pytorch.org/whl/rocm6.1

# Application dependencies
COPY requirements.txt /app/requirements.txt
RUN pip3 install --no-cache-dir -r /app/requirements.txt

# Pre-download model weights at build time
# Uses CPU to avoid needing GPU during docker build
RUN python3 -c "\
from kokoro import KModel; \
print('Downloading Kokoro model weights...'); \
KModel(repo_id='hexgrad/Kokoro-82M'); \
print('Model download complete.')"

WORKDIR /app
COPY server.py config.yaml entrypoint.sh ./
RUN chmod +x entrypoint.sh

EXPOSE 10300

ENTRYPOINT ["./entrypoint.sh"]
