Spaces:
Sleeping
Sleeping
Commit ·
60f20a4
1
Parent(s): f09a460
Fix: writable data dir for HF Spaces, pin bcrypt 4.0.1
Browse files- app/database.py +8 -2
- app/main.py +2 -2
- requirements.txt +1 -0
app/database.py
CHANGED
|
@@ -5,8 +5,14 @@ from sqlalchemy import create_engine
|
|
| 5 |
from sqlalchemy.orm import sessionmaker, declarative_base
|
| 6 |
|
| 7 |
BASE_DIR = Path(__file__).resolve().parent
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
DATABASE_URL = os.environ.get("DATABASE_URL", f"sqlite:///{DB_PATH}")
|
| 12 |
|
|
|
|
| 5 |
from sqlalchemy.orm import sessionmaker, declarative_base
|
| 6 |
|
| 7 |
BASE_DIR = Path(__file__).resolve().parent
|
| 8 |
+
|
| 9 |
+
# Use /home/appuser/data on HF Spaces (writable), fall back to local data/ dir
|
| 10 |
+
_home_data = Path.home() / "data"
|
| 11 |
+
_local_data = BASE_DIR.parent / "data"
|
| 12 |
+
DATA_DIR = _home_data if os.environ.get("SPACE_ID") else _local_data
|
| 13 |
+
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
DB_PATH = DATA_DIR / "satellite_app.db"
|
| 16 |
|
| 17 |
DATABASE_URL = os.environ.get("DATABASE_URL", f"sqlite:///{DB_PATH}")
|
| 18 |
|
app/main.py
CHANGED
|
@@ -23,7 +23,7 @@ from .auth import (
|
|
| 23 |
get_user_from_token,
|
| 24 |
verify_password,
|
| 25 |
)
|
| 26 |
-
from .database import Base, engine, get_db
|
| 27 |
from .models import User, DetectionRun
|
| 28 |
from .detection_engine import run_detection
|
| 29 |
|
|
@@ -34,7 +34,7 @@ app = FastAPI(title="Satellite Change Detection", version="1.0.0")
|
|
| 34 |
# Mount static files
|
| 35 |
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
|
| 36 |
TEMPLATES_DIR = Path(__file__).resolve().parent.parent / "templates"
|
| 37 |
-
OVERLAYS_DIR =
|
| 38 |
OVERLAYS_DIR.mkdir(parents=True, exist_ok=True)
|
| 39 |
|
| 40 |
if STATIC_DIR.exists():
|
|
|
|
| 23 |
get_user_from_token,
|
| 24 |
verify_password,
|
| 25 |
)
|
| 26 |
+
from .database import Base, engine, get_db, DATA_DIR
|
| 27 |
from .models import User, DetectionRun
|
| 28 |
from .detection_engine import run_detection
|
| 29 |
|
|
|
|
| 34 |
# Mount static files
|
| 35 |
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
|
| 36 |
TEMPLATES_DIR = Path(__file__).resolve().parent.parent / "templates"
|
| 37 |
+
OVERLAYS_DIR = DATA_DIR / "overlays"
|
| 38 |
OVERLAYS_DIR.mkdir(parents=True, exist_ok=True)
|
| 39 |
|
| 40 |
if STATIC_DIR.exists():
|
requirements.txt
CHANGED
|
@@ -6,6 +6,7 @@ sqlalchemy>=2.0.0
|
|
| 6 |
psycopg2-binary>=2.9.9
|
| 7 |
python-jose[cryptography]>=3.3.0
|
| 8 |
passlib[bcrypt]>=1.7.4
|
|
|
|
| 9 |
pillow>=10.0.0
|
| 10 |
numpy>=1.24.0
|
| 11 |
opencv-python-headless>=4.8.0
|
|
|
|
| 6 |
psycopg2-binary>=2.9.9
|
| 7 |
python-jose[cryptography]>=3.3.0
|
| 8 |
passlib[bcrypt]>=1.7.4
|
| 9 |
+
bcrypt==4.0.1
|
| 10 |
pillow>=10.0.0
|
| 11 |
numpy>=1.24.0
|
| 12 |
opencv-python-headless>=4.8.0
|