# ── Base image ──────────────────────────────────────────────────────────────── FROM python:3.11-slim ENV PYTHONUNBUFFERED=1 # ── Non-root user (required by Hugging Face Spaces) ─────────────────────────── RUN useradd -m -u 1000 user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Fix: point HF cache to the user's writable home so the pre-downloaded model # is found at runtime (same path used in app.py via os.environ.setdefault). ENV HF_HOME=/home/user/.cache/huggingface \ TRANSFORMERS_CACHE=/home/user/.cache/huggingface WORKDIR $HOME/app # ── System dependencies ─────────────────────────────────────────────────────── USER root RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* USER user # ── Python dependencies ─────────────────────────────────────────────────────── COPY --chown=user requirements.txt . # Step 1 — Install PyTorch CPU wheel from its dedicated index RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir \ torch==2.3.1 \ --index-url https://download.pytorch.org/whl/cpu # Step 2 — Install the remaining packages from PyPI RUN pip install --no-cache-dir \ streamlit==1.35.0 \ chronos-forecasting==1.3.0 \ pandas==2.2.2 \ numpy==1.26.4 \ plotly==5.22.0 # ── Pre-download model weights at build time ────────────────────────────────── # Runs as `user` with HF_HOME set above — weights land in the correct cache dir RUN python -c "\ import os; \ os.environ['HF_HOME'] = '/home/user/.cache/huggingface'; \ from chronos import BaseChronosPipeline; \ BaseChronosPipeline.from_pretrained('amazon/chronos-bolt-base', device_map='cpu')" # ── Application code ────────────────────────────────────────────────────────── COPY --chown=user app.py . COPY --chown=user interface.py . # ── Network ─────────────────────────────────────────────────────────────────── EXPOSE 7860 # ── Entrypoint ──────────────────────────────────────────────────────────────── CMD ["streamlit", "run", "interface.py", \ "--server.port=7860", \ "--server.address=0.0.0.0", \ "--browser.gatherUsageStats=false", \ "--server.headless=true"]