Luigi commited on
Commit
08f659b
·
1 Parent(s): 4b95538

add workaround in ensure_weights to deal with persmission error

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -12,6 +12,7 @@ import gc
12
  import io
13
  from contextlib import redirect_stdout, redirect_stderr
14
  import sys, llama_cpp
 
15
 
16
  # ----------------------------------------
17
  # Model configurations: per-size prefixes and repos
@@ -53,17 +54,25 @@ model_cache = {
53
  }
54
 
55
  # Helper to download & symlink weights
 
 
 
56
 
57
- def ensure_weights(size, model_file, clip_file):
58
- cfg = MODELS[size]
59
- if not os.path.exists(model_file):
60
- logging.info(f"Downloading model file {model_file} from {cfg['model_repo']}...")
61
- path = hf_hub_download(repo_id=cfg['model_repo'], filename=model_file)
62
  os.symlink(path, model_file)
63
- if not os.path.exists(clip_file):
64
- logging.info(f"Downloading CLIP file {clip_file} from {cfg['clip_repo']}...")
65
- path = hf_hub_download(repo_id=cfg['clip_repo'], filename=clip_file)
66
- os.symlink(path, clip_file)
 
 
 
 
 
 
 
 
67
  return model_file, clip_file
68
 
69
  # Custom chat handler
 
12
  import io
13
  from contextlib import redirect_stdout, redirect_stderr
14
  import sys, llama_cpp
15
+ import shutil
16
 
17
  # ----------------------------------------
18
  # Model configurations: per-size prefixes and repos
 
54
  }
55
 
56
  # Helper to download & symlink weights
57
+ def ensure_weights(cfg, model_file, clip_file):
58
+ # download into HF cache (now in /tmp/.cache)
59
+ path = hf_hub_download(repo_id=cfg['model_repo'], filename=model_file)
60
 
61
+ # try to link into your working dir, else copy
62
+ try:
 
 
 
63
  os.symlink(path, model_file)
64
+ except (PermissionError, OSError):
65
+ print(f"⚠️ symlink failed, copying {path} {model_file}")
66
+ shutil.copy2(path, model_file)
67
+
68
+ # repeat for clip_file…
69
+ clip_path = hf_hub_download(repo_id=cfg['clip_repo'], filename=clip_file)
70
+ try:
71
+ os.symlink(clip_path, clip_file)
72
+ except (PermissionError, OSError):
73
+ print(f"⚠️ symlink failed, copying {clip_path} → {clip_file}")
74
+ shutil.copy2(clip_path, clip_file)
75
+
76
  return model_file, clip_file
77
 
78
  # Custom chat handler