Spaces:
Paused
Paused
| # ββ Base image ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| FROM python:3.11-slim | |
| # ββ Environment variables βββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # HF_HOME / TRANSFORMERS_CACHE must point to /tmp so they are writable | |
| # under any user (HuggingFace Spaces restricts writes outside /tmp and /home). | |
| ENV HF_HOME=/tmp/hf_cache \ | |
| TRANSFORMERS_CACHE=/tmp/hf_cache \ | |
| HF_DATASETS_CACHE=/tmp/hf_cache/datasets \ | |
| PYTHONUNBUFFERED=1 \ | |
| PORT=7860 | |
| # ββ System dependencies βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # ββ Working directory βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| WORKDIR /app | |
| # ββ Install Python dependencies βββββββββββββββββββββββββββββββββββββββββββββββ | |
| COPY requirements.txt setup.py README.md ./ | |
| COPY src/ ./src/ | |
| RUN pip install --no-cache-dir --upgrade pip \ | |
| && pip install --no-cache-dir -r requirements.txt | |
| # ββ Copy application code ββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| COPY app.py main.py params.yaml ./ | |
| COPY config/ ./config/ | |
| # ββ Create writable runtime directories ββββββββββββββββββββββββββββββββββββββ | |
| # Create artifact dirs and the HF cache dir here (as root) so they already | |
| # exist with correct ownership before we switch to the non-root user. | |
| RUN mkdir -p \ | |
| artifacts/model_trainer \ | |
| artifacts/model_evaluation \ | |
| artifacts/data_ingestion \ | |
| artifacts/data_transformation \ | |
| artifacts/data_validation \ | |
| /tmp/hf_cache \ | |
| && useradd -m -u 1000 appuser \ | |
| && chown -R appuser:appuser /app /tmp/hf_cache | |
| USER appuser | |
| # ββ Port ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # HuggingFace Spaces requires exactly 7860. | |
| EXPOSE 7860 | |
| # ββ Health check ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Returns 200 once model is loaded, 503 while still warming up β both are | |
| # acceptable to the orchestrator (non-5xx codes keep the container alive). | |
| HEALTHCHECK --interval=20s --timeout=10s --start-period=120s --retries=5 \ | |
| CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:7860/', timeout=8)"] | |
| # ββ Start server ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| CMD ["python", "app.py"] | |