# chatterbox-fast — self-contained image. No external/private base: a slim Python
# base + the public chatterbox-tts package on PyPI, which pulls a single
# consistent torch+torchaudio (CUDA wheels) — no torchvision, so none of the
# torch/torchvision version-pinning conflicts a PyTorch base image causes.
#
# The ~6 GB Chatterbox-Turbo weights are NOT baked — they download from
# HuggingFace into HF_HOME on first run. The starter VOICES are baked (see
# voices/) so a fresh container can synthesize out of the box.
FROM python:3.11-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
        ffmpeg libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

ENV HF_HOME=/app/hf_cache \
    CBF_VOICES_DIR=/app/voices \
    CBF_DEFAULT_VOICE=catharine \
    CBF_MODEL_DEVICE=cuda \
    CBF_BIND=0.0.0.0 \
    CBF_PORT=8197 \
    PYTHONUNBUFFERED=1

WORKDIR /app
COPY pyproject.toml README.md ./
COPY chatterbox_fast ./chatterbox_fast
COPY voices ./voices

# torch is already provided by the base image; pip resolves chatterbox-tts +
# the server deps against it.
RUN pip install --no-cache-dir .

EXPOSE 8197
HEALTHCHECK --interval=30s --timeout=10s --start-period=180s --retries=3 \
    CMD python -c "import urllib.request,sys; b=urllib.request.urlopen('http://127.0.0.1:8197/health',timeout=5).read(); sys.exit(0 if b'\"status\":\"ok\"' in b.replace(b' ',b'') else 1)"

CMD ["chatterbox-fast"]
