Spaces:
Sleeping
Sleeping
| # =============== Hugging Face Spaces Official Base (2025) =============== | |
| # This is the exact base image HF recommends for Playwright apps | |
| FROM python:3.10-slim-bookworm | |
| # Set environment variables (critical for headless + no buffering) | |
| ENV DEBIAN_FRONTEND=noninteractive \ | |
| PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright | |
| # Create non-root user (required by Hugging Face security policy) | |
| RUN useradd -m -s /bin/bash appuser | |
| # Install system basics + Playwright dependencies in one layer | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ca-certificates \ | |
| wget \ | |
| gnupg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set workdir | |
| WORKDIR /home/appuser/app | |
| # Copy requirements first (maximizes cache) | |
| COPY requirements.txt . | |
| # Install Python packages | |
| RUN pip install --upgrade --no-cache-dir pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # ========= THIS IS THE MAGIC LINE FOR HUGGING FACE ========= | |
| # Installs Playwright + browsers + ALL system dependencies automatically | |
| RUN pip install playwright && \ | |
| playwright install --with-deps chromium | |
| # =========================================================== | |
| # (We only need Chromium β saves ~300MB vs installing all browsers) | |
| # Copy your app code | |
| COPY . . | |
| # Fix permissions | |
| RUN chown -R appuser:appuser /home/appuser | |
| # Switch to non-root user (mandatory on HF) | |
| USER appuser | |
| # Expose Gradio default port | |
| EXPOSE 7860 | |
| # Healthcheck (HF loves this) | |
| HEALTHCHECK --interval=30s --timeout=5s --start-period=90s --retries=3 \ | |
| CMD wget --no-verbose --tries=1 --spider http://localhost:7860 || exit 1 | |
| # Start the app (standard for Gradio on HF Spaces) | |
| CMD ["python", "app.py"] |