Spaces:
Paused
Paused
File size: 3,560 Bytes
5ff4fb2 9ce51a5 5ff4fb2 9ce51a5 5ff4fb2 9ce51a5 5ff4fb2 9ce51a5 fa32687 5ff4fb2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # ββ 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"]
|