Spaces:
Sleeping
Sleeping
Commit ·
306fa3b
1
Parent(s): 6ec2d12
Fix database path for HF Spaces (use /tmp for writable storage)
Browse files- app/database.py +16 -2
app/database.py
CHANGED
|
@@ -6,6 +6,7 @@ Manages projects and validation history.
|
|
| 6 |
import sqlite3
|
| 7 |
import json
|
| 8 |
import logging
|
|
|
|
| 9 |
from datetime import datetime
|
| 10 |
from pathlib import Path
|
| 11 |
from typing import List, Dict, Optional, Any
|
|
@@ -13,12 +14,25 @@ from typing import List, Dict, Optional, Any
|
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
class ProjectDatabase:
|
| 17 |
"""Database manager for projects and validations."""
|
| 18 |
|
| 19 |
-
def __init__(self, db_path: str =
|
| 20 |
"""Initialize database connection and create tables if needed."""
|
| 21 |
-
self.db_path = db_path
|
| 22 |
self._init_database()
|
| 23 |
|
| 24 |
def _init_database(self):
|
|
|
|
| 6 |
import sqlite3
|
| 7 |
import json
|
| 8 |
import logging
|
| 9 |
+
import os
|
| 10 |
from datetime import datetime
|
| 11 |
from pathlib import Path
|
| 12 |
from typing import List, Dict, Optional, Any
|
|
|
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
|
| 17 |
+
def get_database_path():
|
| 18 |
+
"""Get writable database path based on environment."""
|
| 19 |
+
# Check if running on Hugging Face Spaces
|
| 20 |
+
if os.environ.get("SPACE_ID"):
|
| 21 |
+
# Use /tmp for HF Spaces (writable directory)
|
| 22 |
+
db_dir = "/tmp"
|
| 23 |
+
else:
|
| 24 |
+
# Local development - use current directory
|
| 25 |
+
db_dir = "."
|
| 26 |
+
|
| 27 |
+
return os.path.join(db_dir, "projects.db")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
class ProjectDatabase:
|
| 31 |
"""Database manager for projects and validations."""
|
| 32 |
|
| 33 |
+
def __init__(self, db_path: str = None):
|
| 34 |
"""Initialize database connection and create tables if needed."""
|
| 35 |
+
self.db_path = db_path or get_database_path()
|
| 36 |
self._init_database()
|
| 37 |
|
| 38 |
def _init_database(self):
|