MalikShehram commited on
Commit
e2cd514
Β·
verified Β·
1 Parent(s): 82dce4b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +39 -17
Dockerfile CHANGED
@@ -1,40 +1,62 @@
1
- # Use a highly optimized, clean modern Python image foundation
2
  FROM python:3.11-slim
3
 
4
- # Enforce immediate log flushing to prevent output tracking buffering delays
5
  ENV PYTHONUNBUFFERED=1
6
 
7
- # Hugging Face requires a non-root user for security and file caching
8
  RUN useradd -m -u 1000 user
9
- USER user
10
  ENV HOME=/home/user \
11
  PATH=/home/user/.local/bin:$PATH
12
 
 
 
 
 
 
13
  WORKDIR $HOME/app
14
 
15
- # Switch to root temporarily to install system dependencies
16
  USER root
17
  RUN apt-get update && apt-get install -y --no-install-recommends \
18
- build-essential \
19
  && rm -rf /var/lib/apt/lists/*
20
  USER user
21
 
22
- # Copy requirements file first to exploit Docker layer caching systems
23
  COPY --chown=user requirements.txt .
24
 
25
- # Upgrade pip and install libraries
26
  RUN pip install --no-cache-dir --upgrade pip && \
27
- pip install --no-cache-dir -r requirements.txt
28
-
29
- # Pre-download the Hugging Face model during the build phase so it doesn't cause startup timeouts
30
- RUN python -c "from chronos import BaseChronosPipeline; BaseChronosPipeline.from_pretrained('amazon/chronos-bolt-base')"
31
-
32
- # Copy the core script and frontend code layers into the deployment engine
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  COPY --chown=user app.py .
34
  COPY --chown=user interface.py .
35
 
36
- # Streamlit network routing configured specifically for Hugging Face Spaces
37
  EXPOSE 7860
38
 
39
- # Run the app on Port 7860 and disable Streamlit telemetry to prevent silent hanging
40
- CMD ["streamlit", "run", "interface.py", "--server.port=7860", "--server.address=0.0.0.0", "--browser.gatherUsageStats=false", "--server.headless=true"]
 
 
 
 
 
1
+ # ── Base image ────────────────────────────────────────────────────────────────
2
  FROM python:3.11-slim
3
 
 
4
  ENV PYTHONUNBUFFERED=1
5
 
6
+ # ── Non-root user (required by Hugging Face Spaces) ───────────────────────────
7
  RUN useradd -m -u 1000 user
 
8
  ENV HOME=/home/user \
9
  PATH=/home/user/.local/bin:$PATH
10
 
11
+ # Fix: point HF cache to the user's writable home so the pre-downloaded model
12
+ # is found at runtime (same path used in app.py via os.environ.setdefault).
13
+ ENV HF_HOME=/home/user/.cache/huggingface \
14
+ TRANSFORMERS_CACHE=/home/user/.cache/huggingface
15
+
16
  WORKDIR $HOME/app
17
 
18
+ # ── System dependencies ───────────────────────────────────────────────────────
19
  USER root
20
  RUN apt-get update && apt-get install -y --no-install-recommends \
21
+ build-essential \
22
  && rm -rf /var/lib/apt/lists/*
23
  USER user
24
 
25
+ # ── Python dependencies ───────────────────────────────────────────────────────
26
  COPY --chown=user requirements.txt .
27
 
28
+ # Step 1 β€” Install PyTorch CPU wheel from its dedicated index
29
  RUN pip install --no-cache-dir --upgrade pip && \
30
+ pip install --no-cache-dir \
31
+ torch==2.3.1 \
32
+ --index-url https://download.pytorch.org/whl/cpu
33
+
34
+ # Step 2 β€” Install the remaining packages from PyPI
35
+ RUN pip install --no-cache-dir \
36
+ streamlit==1.35.0 \
37
+ chronos-forecasting==1.3.0 \
38
+ pandas==2.2.2 \
39
+ numpy==1.26.4 \
40
+ plotly==5.22.0
41
+
42
+ # ── Pre-download model weights at build time ──────────────────────────────────
43
+ # Runs as `user` with HF_HOME set above β€” weights land in the correct cache dir
44
+ RUN python -c "\
45
+ import os; \
46
+ os.environ['HF_HOME'] = '/home/user/.cache/huggingface'; \
47
+ from chronos import BaseChronosPipeline; \
48
+ BaseChronosPipeline.from_pretrained('amazon/chronos-bolt-base', device_map='cpu')"
49
+
50
+ # ── Application code ──────────────────────────────────────────────────────────
51
  COPY --chown=user app.py .
52
  COPY --chown=user interface.py .
53
 
54
+ # ── Network ───────────────────────────────────────────────────────────────────
55
  EXPOSE 7860
56
 
57
+ # ── Entrypoint ────────────────────────────────────────────────────────────────
58
+ CMD ["streamlit", "run", "interface.py", \
59
+ "--server.port=7860", \
60
+ "--server.address=0.0.0.0", \
61
+ "--browser.gatherUsageStats=false", \
62
+ "--server.headless=true"]