Spaces:
Sleeping
Sleeping
| # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker | |
| # you will also find guides on how best to write your Dockerfile | |
| FROM python:3.11-slim | |
| # Prevent Python from writing pyc files and buffering stdout | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| # Install system dependencies for matplotlib, networkx, and compilation | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| libfreetype6-dev \ | |
| libpng-dev \ | |
| libjpeg-dev \ | |
| libopenblas-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Hugging Face Spaces runs containers as UID 1000. | |
| # Create the user now to avoid permission issues at runtime. | |
| RUN useradd -m -u 1000 user | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy requirements first (for Docker layer caching) | |
| COPY --chown=user ./requirements.txt requirements.txt | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy the entire application with correct ownership | |
| COPY --chown=user . /app | |
| # Switch to non-root user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Expose the port Hugging Face Spaces expects | |
| EXPOSE 7860 | |
| # Run the Flask application | |
| CMD ["python", "app.py"] | |