Spaces:
Sleeping
Sleeping
| """ | |
| Path configuration for local vs deployed environments. | |
| This module handles different paths for local development vs deployed (HF Spaces) environments. | |
| """ | |
| import os | |
| from pathlib import Path | |
| # Determine if we're in a deployed environment (HF Spaces/Docker) or local | |
| # Check for environment variable or Docker-like paths | |
| IS_DEPLOYED = ( | |
| os.getenv("DEPLOYED", "false").lower() == "true" or | |
| os.path.exists("/app") or | |
| os.getenv("SPACES_ID") is not None or | |
| os.path.exists("/.dockerenv") | |
| ) | |
| # PROJECT_DIR: Base directory for application files | |
| # In deployed: /app, in local: current working directory or project root | |
| if IS_DEPLOYED: | |
| PROJECT_DIR = Path("/app") | |
| else: | |
| # For local development, use current working directory or find project root | |
| cwd = Path.cwd() | |
| # Try to find project root (directory containing this src/ folder) | |
| project_root = cwd | |
| while project_root != project_root.parent: | |
| if (project_root / "src" / "config").exists(): | |
| break | |
| project_root = project_root.parent | |
| PROJECT_DIR = project_root | |
| # Cache directories - different for local vs deployed | |
| # Local: Use default user cache locations (don't override) | |
| # Deployed: Use PROJECT_DIR/.cache | |
| if IS_DEPLOYED: | |
| CACHE_DIR = PROJECT_DIR / ".cache" | |
| HF_CACHE_DIR = CACHE_DIR / "huggingface" | |
| STREAMLIT_CACHE_DIR = CACHE_DIR / "streamlit" | |
| else: | |
| # For local, use default user cache (let libraries use their defaults) | |
| HF_CACHE_DIR = None # Will use HF defaults (~/.cache/huggingface) | |
| STREAMLIT_CACHE_DIR = None # Will use Streamlit defaults | |
| # Application directories | |
| FEEDBACK_DIR = PROJECT_DIR / "feedback" | |
| CONVERSATIONS_DIR = PROJECT_DIR / "conversations" | |
| STREAMLIT_CONFIG_DIR = PROJECT_DIR / ".streamlit" | |
| # Log the configuration | |
| if __name__ == "__main__": | |
| print(f"IS_DEPLOYED: {IS_DEPLOYED}") | |
| print(f"PROJECT_DIR: {PROJECT_DIR}") | |
| print(f"HF_CACHE_DIR: {HF_CACHE_DIR}") | |
| print(f"FEEDBACK_DIR: {FEEDBACK_DIR}") | |
| print(f"CONVERSATIONS_DIR: {CONVERSATIONS_DIR}") | |