Spaces:
Sleeping
Sleeping
| """ | |
| Centralized storage path configuration. | |
| On Hugging Face Spaces (Docker), persistent storage is mounted at /data. | |
| Locally, falls back to ./local_data so the repo stays clean. | |
| """ | |
| import os | |
| from pathlib import Path | |
| def _is_hf_space(): | |
| """Detect if running inside a Hugging Face Space.""" | |
| return os.getenv("SPACE_ID") is not None | |
| def get_storage_root(): | |
| """Return the root directory for all persistent runtime data.""" | |
| if _is_hf_space(): | |
| return Path("/data") | |
| return Path("./local_data") | |
| def get_pdf_dir(): | |
| """Directory where uploaded PDFs are stored.""" | |
| p = get_storage_root() / "pdfs" | |
| p.mkdir(parents=True, exist_ok=True) | |
| return p | |
| def get_chroma_dir(): | |
| """Directory where ChromaDB stores its database.""" | |
| p = get_storage_root() / "chroma" | |
| p.mkdir(parents=True, exist_ok=True) | |
| return p | |
| def ensure_dirs(): | |
| """Create all required directories at startup.""" | |
| get_pdf_dir() | |
| get_chroma_dir() | |