Marcin-XStudio commited on
Commit
1dabac0
·
1 Parent(s): 10fbe68

ad correct MODEL PATH

Browse files
Files changed (2) hide show
  1. Dockerfile +10 -10
  2. app.py +16 -10
Dockerfile CHANGED
@@ -2,28 +2,28 @@
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 cache dir and make it world-writable
11
- RUN mkdir -p /app/model_cache && chmod 777 /app/model_cache
12
 
13
- # 3) Download the model into /app/model_cache
14
  RUN python - <<EOF
15
  from huggingface_hub import snapshot_download
16
- # this writes under /app/model_cache/models--numind--NuExtract-1.5-tiny/...
17
  snapshot_download(
18
  repo_id="numind/NuExtract-1.5-tiny",
19
- cache_dir="/app/model_cache"
 
 
20
  )
21
  EOF
 
 
22
 
23
- # 3b) Fix permissions on everything we just downloaded
24
- RUN chmod -R 777 /app/model_cache
25
-
26
- # 4) Copy your code
27
  COPY . .
28
 
29
  ENV PORT=7860
 
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
app.py CHANGED
@@ -15,17 +15,23 @@ from huggingface_hub import snapshot_download
15
  load_dotenv()
16
  app = FastAPI()
17
 
18
-
19
  model_name = "numind/NuExtract-1.5-tiny"
20
- MODEL_CACHE_DIR = "/app/model_cache"
21
- model_cache_path = snapshot_download(
22
- repo_id="numind/NuExtract-1.5-tiny",
23
- cache_dir=MODEL_CACHE_DIR
24
- )
 
 
 
 
 
 
25
 
26
- print(">>> MODEL CACHE PATH:", model_cache_path, os.listdir(model_cache_path))
27
 
28
- device = "gpu" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
29
  dtype = torch.float16 if device in ("mps", "gpu") else torch.float32
30
 
31
  @app.on_event("startup")
@@ -44,14 +50,14 @@ def load_model():
44
  # model_name, torch_dtype=dtype, trust_remote_code=True
45
  # )
46
  model = AutoModelForCausalLM.from_pretrained(
47
- model_cache_path,
48
  local_files_only=True,
49
  torch_dtype=dtype,
50
  trust_remote_code=True
51
  ).to(device).eval()
52
  # tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
53
  tokenizer = AutoTokenizer.from_pretrained(
54
- model_cache_path,
55
  local_files_only=True,
56
  trust_remote_code=True
57
  )
 
15
  load_dotenv()
16
  app = FastAPI()
17
 
18
+ # // FOR RUNNING IN SPACES
19
  model_name = "numind/NuExtract-1.5-tiny"
20
+ # Path inside your container
21
+ MODEL_PATH = "/app/model/models--numind--NuExtract-1.5-tiny/snapshots/<commit_hash>"
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))
33
 
34
+ device = "gpu" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
35
  dtype = torch.float16 if device in ("mps", "gpu") else torch.float32
36
 
37
  @app.on_event("startup")
 
50
  # model_name, torch_dtype=dtype, trust_remote_code=True
51
  # )
52
  model = AutoModelForCausalLM.from_pretrained(
53
+ MODEL_PATH,
54
  local_files_only=True,
55
  torch_dtype=dtype,
56
  trust_remote_code=True
57
  ).to(device).eval()
58
  # tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
59
  tokenizer = AutoTokenizer.from_pretrained(
60
+ MODEL_PATH,
61
  local_files_only=True,
62
  trust_remote_code=True
63
  )