FROM python:3.10-slim

# System deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg git build-essential \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user (HF Spaces requirement)
RUN useradd -m -u 1000 user
WORKDIR /home/user/app

# Install numpy FIRST so pkuseg can build
RUN pip install --no-cache-dir numpy "setuptools<82"

# Install rho-tts from PyPI with all extras
RUN pip install --no-cache-dir "rho-tts[all]" "gradio[oauth]==6.9.0" "uvicorn>=0.14.0" spaces

# Copy only the app entry point
COPY app.py .

# Switch to non-root user
USER user

ENV GRADIO_SERVER_NAME=0.0.0.0
ENV GRADIO_SERVER_PORT=7860
EXPOSE 7860

CMD ["python", "-m", "rho_tts.ui"]
