FROM python:3.12-slim

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

WORKDIR /app

COPY pyproject.toml .
RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu && \
    pip install --no-cache-dir resemblyzer silero-vad scipy numpy && \
    pip install --no-cache-dir fastapi uvicorn[standard] pydantic-settings httpx websockets livekit-api

COPY app/ app/

# Pre-download VAD and resemblyzer models into the image
RUN python -c "import torch; torch.hub.load('snakers4/silero-vad', 'silero_vad', trust_repo=True)" && \
    python -c "from resemblyzer import VoiceEncoder; VoiceEncoder()"

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