# ─────────────────────────────────────────────────────────────
# DemIA Living Lab — Hugging Face TTS Starter
# Builds a container that serves the FastAPI TTS service.
# ─────────────────────────────────────────────────────────────

# Use a slim Python 3.11 base; CPU-only torch keeps the image smaller.
# Swap the FROM line for pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
# if you need GPU support.
FROM python:3.11-slim

# Install system packages required by librosa / soundfile / ffmpeg
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    libsndfile1 \
    git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy dependency manifest first so Docker can cache this layer
COPY requirements.txt .

# Install Python deps (CPU-only torch wheel to keep image lean)
RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir torch==2.1.0+cpu \
        --index-url https://download.pytorch.org/whl/cpu \
    && pip install --no-cache-dir -r requirements.txt

# Copy project source
COPY . .

# Create output directory
RUN mkdir -p outputs

# Expose FastAPI port
EXPOSE 8000

# Default: start the API server.
# Override CMD to run the Gradio UI: python app/app.py
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"]
