FROM python:3.10-slim # Force Python version for HuggingFace Spaces ENV PYTHON_VERSION=3.10 # System dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libsndfile1 \ ffmpeg \ git \ && rm -rf /var/lib/apt/lists/* # Create app user RUN useradd -m -u 1000 appuser # Working directory WORKDIR /app # Copy requirements first for caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy application files COPY app.py . COPY tts_engine.py . COPY file_handler.py . COPY setup_speakers.py . COPY README.md . # Create directories RUN mkdir -p speakers temp_audio && \ chown -R appuser:appuser /app # Switch to app user USER appuser # Generate speaker files RUN python setup_speakers.py # Expose port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=120s \ CMD python -c "import requests; requests.get('http://localhost:7860')" || exit 1 # Start app CMD ["python", "app.py"]