Spaces:
Sleeping
Sleeping
| # Use an official Python runtime as a parent image | |
| # HuggingFace Edition: Optimized for HF free-tier services | |
| FROM python:3.11-slim AS base | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
| # HuggingFace optimization: Constrain threads for HF Spaces | |
| OMP_NUM_THREADS=1 \ | |
| OPENBLAS_NUM_THREADS=1 \ | |
| MKL_NUM_THREADS=1 \ | |
| NUMEXPR_NUM_THREADS=1 \ | |
| TOKENIZERS_PARALLELISM=false \ | |
| # Enable HF services by default | |
| ENABLE_HF_SERVICES=true \ | |
| ENABLE_HF_PROCESSING=true | |
| WORKDIR /app | |
| # Install build essentials only if needed for wheels (kept minimal) | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| procps \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Configure pip to suppress root user warnings | |
| RUN mkdir -p /root/.pip | |
| COPY pip.conf /root/.pip/pip.conf | |
| COPY constraints.txt requirements.txt ./ | |
| RUN python -m pip install --upgrade pip setuptools wheel \ | |
| && pip install --no-cache-dir -r requirements.txt -c constraints.txt --only-binary=:all: || \ | |
| pip install --no-cache-dir -r requirements.txt -c constraints.txt | |
| # Application source | |
| COPY app.py ./app.py | |
| COPY templates ./templates | |
| COPY static ./static | |
| COPY src ./src | |
| COPY synthetic_policies ./synthetic_policies | |
| COPY data ./data | |
| COPY scripts ./scripts | |
| COPY run.sh ./run.sh | |
| COPY gunicorn.conf.py ./gunicorn.conf.py | |
| RUN chmod +x run.sh || true | |
| EXPOSE 8080 | |
| # Run the app via Gunicorn binding to 0.0.0.0:8080 | |
| # Optimized for HuggingFace Spaces with HF services | |
| # to reduce memory usage on small instances. | |
| CMD ["gunicorn", "-b", "0.0.0.0:8080", "-w", "2", "--threads", "2", "src.app_factory:create_app()"] | |
| # Optional dev stage for local tooling (not used in final image) | |
| FROM base AS dev | |
| COPY dev-requirements.txt ./dev-requirements.txt | |
| RUN pip install --no-cache-dir -r dev-requirements.txt -c constraints.txt || true | |