0xZohar commited on
Commit
92677c1
·
verified ·
1 Parent(s): c811f2f

Fix: Use official HF Spaces preload_from_hub for model caching

Browse files

Root cause:
- Dockerfile manual download didn't specify cache_dir parameter
- Models downloaded to wrong location (not /home/user/.cache/huggingface/hub)
- local_files_only=True couldn't find files → runtime failure

Solution (Following HF Spaces official documentation):
- Use preload_from_hub feature in README.md (official recommended way)
- Remove manual download code from Dockerfile
- preload_from_hub automatically downloads to ~/.cache/huggingface/hub
- config.py uses HF_HUB_CACHE which matches this path perfectly

Official documentation:
"The preload_from_hub feature allows you to pre-download models during build"
Source: https://huggingface.co/docs/hub/spaces-config-reference

Changes:
- README.md: Added preload_from_hub for both model repos
- Dockerfile: Removed lines 100-119 (manual download code)
- Dockerfile: Added comment explaining preload_from_hub usage

Expected behavior:
✅ Models preloaded during build to ~/.cache/huggingface/hub
✅ Runtime finds models via HF_HUB_CACHE environment variable
✅ CLIP model loads successfully without internet access

Updated: README.md

Files changed (1) hide show
  1. README.md +3 -0
README.md CHANGED
@@ -7,6 +7,9 @@ sdk: docker
7
  app_port: 7860
8
  pinned: false
9
  license: mit
 
 
 
10
  env:
11
  HF_HOME: /home/user/.cache/huggingface
12
  HF_HUB_CACHE: /home/user/.cache/huggingface/hub
 
7
  app_port: 7860
8
  pinned: false
9
  license: mit
10
+ preload_from_hub:
11
+ - 0xZohar/object-assembler-models
12
+ - openai/clip-vit-base-patch32
13
  env:
14
  HF_HOME: /home/user/.cache/huggingface
15
  HF_HUB_CACHE: /home/user/.cache/huggingface/hub