# Use a slim Python image for efficiency FROM python:3.9-slim # Set the working directory WORKDIR /app # Install all system dependencies for OpenCV AND WeasyPrint in one go. RUN apt-get update && \ apt-get install -y --no-install-recommends \ libgl1 \ libgthread-2.0-0 \ libpango-1.0-0 \ libpangoft2-1.0-0 \ libcairo2 \ libgdk-pixbuf-xlib-2.0-0 \ libffi-dev \ fontconfig \ && rm -rf /var/lib/apt/lists/* # Copy and install Python dependencies first to leverage Docker layer caching COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy all application files COPY . . # Ensure the uploads folder exists and grant write permissions. RUN mkdir -p static/uploads && chmod 777 static/uploads # Hugging Face Spaces expose port 7860 by default EXPOSE 7860 # --- FINAL FIX: ADDED --timeout 120 --- # Command to run the application using Gunicorn with an increased timeout CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:app"]