kaveh commited on
Commit
2b4a83e
·
1 Parent(s): 6cbe52d

changed dockerfile

Browse files
Files changed (2) hide show
  1. Dockerfile +2 -20
  2. download_ckp.py +19 -0
Dockerfile CHANGED
@@ -22,7 +22,7 @@ RUN pip install --no-cache-dir \
22
  huggingface_hub
23
 
24
  # Copy app code (chown for HF Spaces permissions)
25
- COPY --chown=user:user app.py predictor.py ./
26
  COPY --chown=user:user models/ models/
27
  COPY --chown=user:user utils/ utils/
28
  COPY --chown=user:user config/ config/
@@ -33,25 +33,7 @@ RUN mkdir -p ckp && chown user:user ckp
33
  # Set HF_MODEL_REPO env to your model repo, e.g. kaveh/Shape2Force
34
  ARG HF_MODEL_REPO=kaveh/Shape2Force
35
  ENV HF_MODEL_REPO=${HF_MODEL_REPO}
36
-
37
- RUN python -c "
38
- import os
39
- from pathlib import Path
40
- ckp = Path('/app/ckp')
41
- if not list(ckp.glob('*.pth')):
42
- try:
43
- from huggingface_hub import hf_hub_download, list_repo_files
44
- repo = os.environ.get('HF_MODEL_REPO', 'kaveh/Shape2Force')
45
- files = list_repo_files(repo)
46
- pth_files = [f for f in files if f.startswith('ckp/') and f.endswith('.pth')]
47
- for f in pth_files:
48
- hf_hub_download(repo_id=repo, filename=f, local_dir='/app')
49
- print('Downloaded checkpoints from', repo)
50
- except Exception as e:
51
- print('Could not download checkpoints:', e)
52
- else:
53
- print('Checkpoints already present')
54
- "
55
 
56
  # Ensure ckp contents are readable by user
57
  RUN chown -R user:user ckp
 
22
  huggingface_hub
23
 
24
  # Copy app code (chown for HF Spaces permissions)
25
+ COPY --chown=user:user app.py predictor.py download_ckp.py ./
26
  COPY --chown=user:user models/ models/
27
  COPY --chown=user:user utils/ utils/
28
  COPY --chown=user:user config/ config/
 
33
  # Set HF_MODEL_REPO env to your model repo, e.g. kaveh/Shape2Force
34
  ARG HF_MODEL_REPO=kaveh/Shape2Force
35
  ENV HF_MODEL_REPO=${HF_MODEL_REPO}
36
+ RUN python download_ckp.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  # Ensure ckp contents are readable by user
39
  RUN chown -R user:user ckp
download_ckp.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Download checkpoints from Hugging Face if ckp is empty (for Space deployment)."""
2
+ import os
3
+ from pathlib import Path
4
+
5
+ ckp = Path("/app/ckp")
6
+ if not list(ckp.glob("*.pth")):
7
+ try:
8
+ from huggingface_hub import hf_hub_download, list_repo_files
9
+
10
+ repo = os.environ.get("HF_MODEL_REPO", "kaveh/Shape2Force")
11
+ files = list_repo_files(repo)
12
+ pth_files = [f for f in files if f.startswith("ckp/") and f.endswith(".pth")]
13
+ for f in pth_files:
14
+ hf_hub_download(repo_id=repo, filename=f, local_dir="/app")
15
+ print("Downloaded checkpoints from", repo)
16
+ except Exception as e:
17
+ print("Could not download checkpoints:", e)
18
+ else:
19
+ print("Checkpoints already present")