File size: 1,299 Bytes
fc7db98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1a8bd1
 
fc7db98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""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"))