Spaces:
Sleeping
Sleeping
Ara Yeroyan
commited on
Commit
·
20d814d
1
Parent(s):
907678b
add deployment level path and ENV routing
Browse files- src/config/paths.py +59 -0
src/config/paths.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Path configuration for local vs deployed environments.
|
| 3 |
+
|
| 4 |
+
This module handles different paths for local development vs deployed (HF Spaces) environments.
|
| 5 |
+
"""
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
# Determine if we're in a deployed environment (HF Spaces/Docker) or local
|
| 10 |
+
# Check for environment variable or Docker-like paths
|
| 11 |
+
IS_DEPLOYED = (
|
| 12 |
+
os.getenv("DEPLOYED", "false").lower() == "true" or
|
| 13 |
+
os.path.exists("/app") or
|
| 14 |
+
os.getenv("SPACES_ID") is not None or
|
| 15 |
+
os.path.exists("/.dockerenv")
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# PROJECT_DIR: Base directory for application files
|
| 19 |
+
# In deployed: /app, in local: current working directory or project root
|
| 20 |
+
if IS_DEPLOYED:
|
| 21 |
+
PROJECT_DIR = Path("/app")
|
| 22 |
+
else:
|
| 23 |
+
# For local development, use current working directory or find project root
|
| 24 |
+
cwd = Path.cwd()
|
| 25 |
+
# Try to find project root (directory containing this src/ folder)
|
| 26 |
+
project_root = cwd
|
| 27 |
+
while project_root != project_root.parent:
|
| 28 |
+
if (project_root / "src" / "config").exists():
|
| 29 |
+
break
|
| 30 |
+
project_root = project_root.parent
|
| 31 |
+
PROJECT_DIR = project_root
|
| 32 |
+
|
| 33 |
+
# Cache directories - different for local vs deployed
|
| 34 |
+
# Local: Use default user cache locations (don't override)
|
| 35 |
+
# Deployed: Use PROJECT_DIR/.cache
|
| 36 |
+
if IS_DEPLOYED:
|
| 37 |
+
CACHE_DIR = PROJECT_DIR / ".cache"
|
| 38 |
+
HF_CACHE_DIR = CACHE_DIR / "huggingface"
|
| 39 |
+
STREAMLIT_CACHE_DIR = CACHE_DIR / "streamlit"
|
| 40 |
+
else:
|
| 41 |
+
# For local, use default user cache (let libraries use their defaults)
|
| 42 |
+
HF_CACHE_DIR = None # Will use HF defaults (~/.cache/huggingface)
|
| 43 |
+
STREAMLIT_CACHE_DIR = None # Will use Streamlit defaults
|
| 44 |
+
|
| 45 |
+
# Application directories
|
| 46 |
+
FEEDBACK_DIR = PROJECT_DIR / "feedback"
|
| 47 |
+
CONVERSATIONS_DIR = PROJECT_DIR / "conversations"
|
| 48 |
+
STREAMLIT_CONFIG_DIR = PROJECT_DIR / ".streamlit"
|
| 49 |
+
|
| 50 |
+
# Log the configuration
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
print(f"IS_DEPLOYED: {IS_DEPLOYED}")
|
| 53 |
+
print(f"PROJECT_DIR: {PROJECT_DIR}")
|
| 54 |
+
print(f"HF_CACHE_DIR: {HF_CACHE_DIR}")
|
| 55 |
+
print(f"FEEDBACK_DIR: {FEEDBACK_DIR}")
|
| 56 |
+
print(f"CONVERSATIONS_DIR: {CONVERSATIONS_DIR}")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|