Marcin-XStudio commited on
Commit
154243f
·
1 Parent(s): 189d897

create flat folder

Browse files
Files changed (2) hide show
  1. Dockerfile +19 -12
  2. app.py +5 -5
Dockerfile CHANGED
@@ -1,29 +1,36 @@
1
- # Dockerfile
2
  FROM python:3.10-slim
3
  WORKDIR /app
4
 
5
- # 1) Install HF tooling + your 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) Create a world-writable cache directory
11
- RUN mkdir -p /app/model && chmod 777 /app/model
12
 
13
- # 3) Download the entire model into /app/model (build time)
14
  RUN python - <<EOF
15
  from huggingface_hub import snapshot_download
16
- snapshot_download(
 
17
  repo_id="numind/NuExtract-1.5-tiny",
18
- cache_dir="/app", # places under /app/models--numind--NuExtract-1.5-tiny/…
19
- local_dir="model", # so final: /app/model/models--…/snapshots/<hash>/
20
- local_dir_use_symlinks=False # ensure actual files, no symlinks needed
21
  )
 
 
 
 
 
 
 
 
 
22
  EOF
23
- # 3b) Make sure perms survive into runtime
24
- RUN chmod -R 755 /app/model
25
 
26
- # 4) Copy your FastAPI code
27
  COPY . .
28
 
29
  ENV PORT=7860
 
 
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
app.py CHANGED
@@ -18,15 +18,15 @@ app = FastAPI()
18
  # // FOR RUNNING IN SPACES
19
  model_name = "numind/NuExtract-1.5-tiny"
20
  # Path inside your container
21
- MODEL_PATH = "/app/model_cache/models--numind--NuExtract-1.5-tiny/snapshots/df52efb3109d324cd52b30728f9e3fdedf19f742"
22
  # If you used local_dir="model", snapshot_download will still create models--… subfolder.
23
  # You can also symlink or copy it to /app/model directly in Dockerfile.
24
 
25
- # // FOR RUNNING LOCALLY
26
- # MODEL_CACHE_DIR = "/app/model_cache"
27
  # model_cache_path = snapshot_download(
28
  # repo_id="numind/NuExtract-1.5-tiny",
29
- # cache_dir=MODEL_CACHE_DIR
30
  # )
31
 
32
  print(">>> MODEL CACHE PATH:", MODEL_PATH, os.listdir(MODEL_PATH))
@@ -61,7 +61,7 @@ def load_model():
61
  local_files_only=True,
62
  trust_remote_code=True
63
  )
64
- print("Model and tokenizer loaded.", flush=True)
65
 
66
  def predict_NuExtract(texts, template, batch_size=10, max_length=5096, max_new_tokens=1024):
67
  print("Starting NuExtract prediction...", flush=True)
 
18
  # // FOR RUNNING IN SPACES
19
  model_name = "numind/NuExtract-1.5-tiny"
20
  # Path inside your container
21
+ # MODEL_PATH = "/app/model_cache/models--numind--NuExtract-1.5-tiny/snapshots/df52efb3109d324cd52b30728f9e3fdedf19f742"
22
  # If you used local_dir="model", snapshot_download will still create models--… subfolder.
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))
 
61
  local_files_only=True,
62
  trust_remote_code=True
63
  )
64
+ print("Model and tokenizer loaded from", MODEL_PATH)
65
 
66
  def predict_NuExtract(texts, template, batch_size=10, max_length=5096, max_new_tokens=1024):
67
  print("Starting NuExtract prediction...", flush=True)