# Use a compatible Python base image FROM python:3.9-slim-bookworm # Set the working directory inside the container WORKDIR /app # First, copy and install Python packages to leverage Docker layer caching COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Now, install Playwright's system dependencies and the Chromium browser # This is much cleaner and more reliable than the wkhtmltopdf process. RUN playwright install-deps RUN playwright install chromium # Create non-root user as required by HF Spaces RUN useradd -m -u 1000 user # Copy application files (before switching user) COPY --chown=1000:1000 app.py . # Switch to non-root user and set environment USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Expose the port EXPOSE 7860 # Run with gunicorn CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]