Marcin-XStudio commited on
Commit
7329fdd
·
1 Parent(s): 727bef6
Files changed (1) hide show
  1. Dockerfile +14 -19
Dockerfile CHANGED
@@ -8,27 +8,24 @@ ENV HOME="/home/user" \
8
  DOCLING_ARTIFACTS_PATH="$HOME/.cache/docling/models" \
9
  OMP_NUM_THREADS=2
10
 
11
- # 2) Create a non-root user
12
  RUN useradd -m -u 1000 user
13
 
14
- # 3) Install system dependencies
15
  RUN apt-get update && apt-get install -y \
16
  build-essential git libpoppler-cpp-dev poppler-utils \
17
  libmagic-dev python3-dev \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
- # 4) Switch to app directory and copy requirements
21
  WORKDIR $HOME/app
22
- COPY --chown=user: /home/user/app/requirements.txt ./
23
-
24
- # 5) Install Python libs as root (to leverage caching)
25
  RUN pip install --no-cache-dir \
26
  torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu \
27
- huggingface_hub \
28
- accelerate \
29
- && pip install --no-cache-dir -r requirements.txt
30
 
31
- # 6) Prepare caches & ownership before running any prefetch
32
  RUN mkdir -p \
33
  $HOME/.cache/docling/models \
34
  $HF_HUB_CACHE \
@@ -38,24 +35,22 @@ RUN mkdir -p \
38
  $HOME/.cache/huggingface \
39
  $HOME/app/model_cache
40
 
41
- # 7) Switch to non-root and prefetch Docling models
42
  USER user
43
  RUN pip install --no-cache-dir docling \
44
  && docling-tools models download
45
 
46
- # 8) Prefetch the NuExtract model into your app’s model_cache
47
  RUN python - <<EOF
48
  from huggingface_hub import snapshot_download
 
49
  snapshot_download(
50
  repo_id="numind/NuExtract-1.5-tiny",
51
  local_dir="$HOME/app/model_cache",
52
- cache_dir="$HF_HUB_CACHE"
53
  )
54
  EOF
55
 
56
- # 9) Copy the rest of your application
57
- COPY --chown=user: . .
58
-
59
- # 10) Expose and run
60
- ENV PORT=7860
61
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
8
  DOCLING_ARTIFACTS_PATH="$HOME/.cache/docling/models" \
9
  OMP_NUM_THREADS=2
10
 
11
+ # 2) Create non-root user
12
  RUN useradd -m -u 1000 user
13
 
14
+ # 3) System deps
15
  RUN apt-get update && apt-get install -y \
16
  build-essential git libpoppler-cpp-dev poppler-utils \
17
  libmagic-dev python3-dev \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
+ # 4) Copy & install Python deps
21
  WORKDIR $HOME/app
22
+ COPY --chown=user:user requirements.txt ./
 
 
23
  RUN pip install --no-cache-dir \
24
  torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu \
25
+ huggingface_hub accelerate \
26
+ && pip install --no-cache-dir -r requirements.txt
 
27
 
28
+ # 5) Prepare caches and ownership
29
  RUN mkdir -p \
30
  $HOME/.cache/docling/models \
31
  $HF_HUB_CACHE \
 
35
  $HOME/.cache/huggingface \
36
  $HOME/app/model_cache
37
 
38
+ # 6) Switch to non-root and prefetch Docling models
39
  USER user
40
  RUN pip install --no-cache-dir docling \
41
  && docling-tools models download
42
 
43
+ # 7) Prefetch the NuExtract model
44
  RUN python - <<EOF
45
  from huggingface_hub import snapshot_download
46
+ import os
47
  snapshot_download(
48
  repo_id="numind/NuExtract-1.5-tiny",
49
  local_dir="$HOME/app/model_cache",
50
+ cache_dir=os.getenv("HF_HUB_CACHE")
51
  )
52
  EOF
53
 
54
+ # 8) Copy application code and start
55
+ COPY --chown=user:user . .
56
+ CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"]