Spaces:
Sleeping
Sleeping
| """Backend configuration — model path and CORS.""" | |
| from __future__ import annotations | |
| import os | |
| from pathlib import Path | |
| # Repo root (Complexity_level/) when running locally or in Docker /app | |
| REPO_ROOT = Path(__file__).resolve().parents[3] | |
| BACKEND_ROOT = Path(__file__).resolve().parents[1] | |
| def resolve_model_path() -> Path: | |
| """MODEL_PATH env, then overnight_bundle, then exported_models.""" | |
| if env := os.environ.get("MODEL_PATH"): | |
| return Path(env).expanduser().resolve() | |
| candidates = [ | |
| REPO_ROOT / "model", | |
| Path("/app/repo/model"), | |
| Path("/home/user/model"), | |
| REPO_ROOT / "overnight_bundle" / "exported_models" / "deberta_best", | |
| REPO_ROOT / "exported_models" / "deberta_best", | |
| Path("/app/overnight_bundle/exported_models/deberta_best"), | |
| Path("/app/exported_models/deberta_best"), | |
| ] | |
| for path in candidates: | |
| if (path / "model_weights.pt").exists(): | |
| return path | |
| # Return first candidate for error messaging even if weights missing | |
| return candidates[0] | |
| MODEL_PATH = resolve_model_path() | |
| CORS_ORIGINS = [ | |
| o.strip() | |
| for o in os.environ.get("CORS_ORIGINS", "http://localhost:3000,http://127.0.0.1:3000").split(",") | |
| if o.strip() | |
| ] | |
| PORT = int(os.environ.get("PORT", "8000")) | |