Spaces:
Paused
Paused
Fix CLIP loading: Use /data cache for config.py
Browse files- code/cube3d/config.py +5 -29
code/cube3d/config.py
CHANGED
|
@@ -59,38 +59,14 @@ CAR_1K_DIR = DATA_DIR / "car_1k"
|
|
| 59 |
CAR_DATA_DIR = DATA_DIR / "1313个筛选车结构和对照渲染图"
|
| 60 |
|
| 61 |
# HuggingFace model cache directory
|
| 62 |
-
#
|
| 63 |
-
# It does NOT respect HF_HOME environment variable (HF official docs confirmed)
|
| 64 |
if ENVIRONMENT == "huggingface":
|
| 65 |
-
#
|
| 66 |
-
HF_CACHE_DIR = os.
|
| 67 |
print(f"[Config] Using HF cache directory: {HF_CACHE_DIR}")
|
| 68 |
|
| 69 |
-
# Ensure directory exists
|
| 70 |
-
|
| 71 |
-
try:
|
| 72 |
-
cache_path.mkdir(parents=True, exist_ok=True, mode=0o755)
|
| 73 |
-
print(f"[Config] Cache directory created/verified with mode 755")
|
| 74 |
-
except Exception as e:
|
| 75 |
-
print(f"[Config] Warning: Could not set cache directory permissions: {e}")
|
| 76 |
-
|
| 77 |
-
# Clean stale lock files that may prevent model loading
|
| 78 |
-
try:
|
| 79 |
-
lock_files = list(cache_path.glob("**/*.lock"))
|
| 80 |
-
if lock_files:
|
| 81 |
-
print(f"[Config] Found {len(lock_files)} lock files, attempting cleanup...")
|
| 82 |
-
cleaned = 0
|
| 83 |
-
for lock_file in lock_files:
|
| 84 |
-
try:
|
| 85 |
-
lock_file.unlink()
|
| 86 |
-
cleaned += 1
|
| 87 |
-
except Exception as e:
|
| 88 |
-
print(f"[Config] Could not remove {lock_file.name}: {e}")
|
| 89 |
-
print(f"[Config] Cleaned {cleaned}/{len(lock_files)} lock files")
|
| 90 |
-
else:
|
| 91 |
-
print(f"[Config] No stale lock files found")
|
| 92 |
-
except Exception as e:
|
| 93 |
-
print(f"[Config] Lock file cleanup failed: {e}")
|
| 94 |
else:
|
| 95 |
# Local development
|
| 96 |
HF_CACHE_DIR = os.path.expanduser("~/.cache/huggingface")
|
|
|
|
| 59 |
CAR_DATA_DIR = DATA_DIR / "1313个筛选车结构和对照渲染图"
|
| 60 |
|
| 61 |
# HuggingFace model cache directory
|
| 62 |
+
# Use /data for persistent storage (writable in HF Spaces)
|
|
|
|
| 63 |
if ENVIRONMENT == "huggingface":
|
| 64 |
+
# /data is persistent and writable in HF Spaces
|
| 65 |
+
HF_CACHE_DIR = os.getenv("HF_HOME", "/data/.huggingface")
|
| 66 |
print(f"[Config] Using HF cache directory: {HF_CACHE_DIR}")
|
| 67 |
|
| 68 |
+
# Ensure directory exists
|
| 69 |
+
os.makedirs(HF_CACHE_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
else:
|
| 71 |
# Local development
|
| 72 |
HF_CACHE_DIR = os.path.expanduser("~/.cache/huggingface")
|