FROM python:3.12-slim

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

WORKDIR /app

COPY pyproject.toml .
# Install torch CPU-only first (avoids pulling GPU variant), then rest of deps
# silero-vad pip package excluded — runtime uses torch.hub.load instead
RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu && \
    pip install --no-cache-dir resemblyzer scipy numpy && \
    pip install --no-cache-dir fastapi uvicorn[standard] pydantic-settings httpx websockets livekit-api

COPY app/ app/

# Pre-download resemblyzer model (VoiceEncoder downloads ~25MB pretrained weights)
RUN python -c "from resemblyzer import VoiceEncoder; VoiceEncoder()"
# Note: silero-vad model downloads lazily at first container startup via torch.hub

ENV PYTHONUNBUFFERED=1
CMD ["python", "-m", "uvicorn", "app.pipeline.main:app", "--host", "0.0.0.0", "--port", "8300"]
