Spaces:
Runtime error
Runtime error
File size: 993 Bytes
aad7814 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | """Keep temp, HF cache, and scratch I/O on the configured DATA_DIR volume.
Windows returns ``[Errno 22] Invalid argument`` when the system temp drive (often
C:) is nearly full while FAISS / upload / embedding caches still write there.
"""
from __future__ import annotations
import os
from pathlib import Path
from backend.config import settings
def ensure_data_drive_runtime_dirs() -> Path:
"""Point TMP/TEMP and HF caches at ``DATA_DIR`` (safe on D: etc.)."""
root = settings.data_dir_path
tmp = root / "tmp"
tmp.mkdir(parents=True, exist_ok=True)
os.environ["TMP"] = str(tmp)
os.environ["TEMP"] = str(tmp)
hf = root / "hf_cache"
hf.mkdir(parents=True, exist_ok=True)
os.environ.setdefault("HF_HOME", str(hf))
os.environ.setdefault("SENTENCE_TRANSFORMERS_HOME", str(hf / "sentence_transformers"))
os.environ.setdefault("TRANSFORMERS_CACHE", str(hf / "transformers"))
os.environ.setdefault("TORCH_HOME", str(hf / "torch"))
return tmp
|