Spaces:
Running
Running
Commit ·
39f0c54
1
Parent(s): 59e68c5
Fix: Add fallback database path when /data not available in HF Spaces
Browse filesIf HF Persistent Storage is not enabled, /data won't be accessible.
This fix adds a fallback to /tmp/agentgraph for ephemeral storage.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- utils/config.py +18 -5
utils/config.py
CHANGED
|
@@ -53,15 +53,28 @@ if LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY:
|
|
| 53 |
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
|
| 54 |
|
| 55 |
# Database Configuration
|
| 56 |
-
# For HF Spaces, use /data persistent storage directory
|
|
|
|
| 57 |
# For local development, use datasets/db directory
|
| 58 |
def _get_default_db_uri():
|
| 59 |
"""Get default database URI based on environment."""
|
| 60 |
if os.getenv("SPACE_ID"): # HF Spaces
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
else:
|
| 66 |
# Local development - use datasets/db relative to project root
|
| 67 |
project_root = Path(__file__).parent.parent.resolve()
|
|
|
|
| 53 |
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
|
| 54 |
|
| 55 |
# Database Configuration
|
| 56 |
+
# For HF Spaces, use /data persistent storage directory if available
|
| 57 |
+
# Fall back to /tmp if /data is not accessible (Persistent Storage not enabled)
|
| 58 |
# For local development, use datasets/db directory
|
| 59 |
def _get_default_db_uri():
|
| 60 |
"""Get default database URI based on environment."""
|
| 61 |
if os.getenv("SPACE_ID"): # HF Spaces
|
| 62 |
+
# Try to use HF Persistent Storage at /data first
|
| 63 |
+
data_dir = Path("/data")
|
| 64 |
+
try:
|
| 65 |
+
# Check if /data exists and is writable
|
| 66 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 67 |
+
test_file = data_dir / ".write_test"
|
| 68 |
+
test_file.touch()
|
| 69 |
+
test_file.unlink()
|
| 70 |
+
print("✅ Using HF Persistent Storage at /data")
|
| 71 |
+
return "sqlite:////data/agent_monitoring.db"
|
| 72 |
+
except (OSError, PermissionError) as e:
|
| 73 |
+
# Fall back to /tmp if /data is not available
|
| 74 |
+
print(f"⚠️ /data not available ({e}), using /tmp for ephemeral storage")
|
| 75 |
+
tmp_dir = Path("/tmp/agentgraph")
|
| 76 |
+
tmp_dir.mkdir(parents=True, exist_ok=True)
|
| 77 |
+
return f"sqlite:///{tmp_dir}/agent_monitoring.db"
|
| 78 |
else:
|
| 79 |
# Local development - use datasets/db relative to project root
|
| 80 |
project_root = Path(__file__).parent.parent.resolve()
|