FROM python:3.10-slim # Hugging Face Optimized - Lightweight & Stable ENV PYTHONUNBUFFERED=1 ENV HF_SPACE=1 # Install minimal system dependencies RUN apt-get update && apt-get install -y \ curl \ ffmpeg \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy requirements and install COPY requirements.txt . RUN pip install --no-cache-dir --upgrade -r requirements.txt # Create a non-privileged user (Required by Hugging Face) RUN useradd -m -u 1000 user RUN chown -R user:user /app USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Copy application code COPY --chown=user:user . . # Hugging Face uses port 7860 EXPOSE 7860 ENV PORT=7860 # Start the application with optimized settings for limited RAM # We use 1 worker to keep memory usage low on the free tier CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "60"]