Marcin-XStudio commited on
Commit
84a9640
·
1 Parent(s): 154243f
Files changed (2) hide show
  1. Dockerfile +7 -20
  2. app.py +5 -5
Dockerfile CHANGED
@@ -1,36 +1,23 @@
 
1
  FROM python:3.10-slim
2
  WORKDIR /app
3
 
4
- # 1) Install HF tooling & your deps
5
  RUN pip install --no-cache-dir huggingface_hub
6
  COPY requirements.txt .
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
9
- # 2) Create a cache dir
10
- RUN mkdir -p /app/model_cache
11
-
12
- # 3) Download the model into model_cache (build-time)
13
  RUN python - <<EOF
14
  from huggingface_hub import snapshot_download
15
- # downloads into /app/models--numind--NuExtract-1.5-tiny/snapshots/<hash>/
16
- tmp = snapshot_download(
17
  repo_id="numind/NuExtract-1.5-tiny",
18
- cache_dir="/app",
19
- local_dir="model_cache",
20
- local_dir_use_symlinks=False
21
  )
22
- # flatten: move from the hash-folder up into /app/model_cache
23
- import os, shutil, glob
24
- root = os.path.join("/app/model_cache","models--numind--NuExtract-1.5-tiny","snapshots")
25
- # there should be exactly one subdir under root
26
- sub = glob.glob(os.path.join(root, "*"))[0]
27
- for fname in os.listdir(sub):
28
- shutil.move(os.path.join(sub, fname), "/app/model_cache")
29
- # clean up
30
- shutil.rmtree(os.path.join("/app/model_cache","models--numind--NuExtract-1.5-tiny"))
31
  EOF
32
 
33
- # 4) Copy your code
34
  COPY . .
35
 
36
  ENV PORT=7860
 
1
+ # Dockerfile
2
  FROM python:3.10-slim
3
  WORKDIR /app
4
 
5
+ # 1) Install HF tooling & runtime deps
6
  RUN pip install --no-cache-dir huggingface_hub
7
  COPY requirements.txt .
8
  RUN pip install --no-cache-dir -r requirements.txt
9
 
10
+ # 2) Download model at build-time directly into model_cache
 
 
 
11
  RUN python - <<EOF
12
  from huggingface_hub import snapshot_download
13
+ # This writes ALL repo files under /app/model_cache
14
+ snapshot_download(
15
  repo_id="numind/NuExtract-1.5-tiny",
16
+ local_dir="/app/model_cache"
 
 
17
  )
 
 
 
 
 
 
 
 
 
18
  EOF
19
 
20
+ # 3) Copy your FastAPI code
21
  COPY . .
22
 
23
  ENV PORT=7860
app.py CHANGED
@@ -23,11 +23,11 @@ model_name = "numind/NuExtract-1.5-tiny"
23
  # You can also symlink or copy it to /app/model directly in Dockerfile.
24
 
25
 
26
- MODEL_PATH = "/app/model_cache"
27
- # model_cache_path = snapshot_download(
28
- # repo_id="numind/NuExtract-1.5-tiny",
29
- # cache_dir=MODEL_PATH
30
- # )
31
 
32
  print(">>> MODEL CACHE PATH:", MODEL_PATH, os.listdir(MODEL_PATH))
33
 
 
23
  # You can also symlink or copy it to /app/model directly in Dockerfile.
24
 
25
 
26
+ # MODEL_PATH = "/app/model_cache"
27
+ model_cache_path = snapshot_download(
28
+ repo_id="numind/NuExtract-1.5-tiny",
29
+ local_dir="/app/model_cache" # <-- direct destination
30
+ )
31
 
32
  print(">>> MODEL CACHE PATH:", MODEL_PATH, os.listdir(MODEL_PATH))
33