File size: 2,393 Bytes
ac5551d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aabfb3b
99e3f1b
ac5551d
 
 
 
8302f42
99e3f1b
ac5551d
 
99e3f1b
ac5551d
 
 
 
 
 
 
 
99e3f1b
ac5551d
 
 
8302f42
ac5551d
 
 
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
42
43
44
45
46
47
48
49
50
"""
config.py β€” Centralized application settings.
All tuneable knobs live here; override via environment variables.
"""
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        case_sensitive=False,
    )

    # ── App ───────────────────────────────────────────────────────────
    app_name: str = "MLForge Platform"
    version: str = "1.0.0"
    debug: bool = False

    # ── API ───────────────────────────────────────────────────────────
    host: str = "0.0.0.0"
    port: int = 7860  # Default for HF Spaces
    cors_origins: list[str] = ["*"]

    # ── Storage ───────────────────────────────────────────────────────
    base_dir: Path = Path(__file__).resolve().parents[1]
    data_dir: Path = base_dir / "data"
    logs_dir: Path = data_dir / "logs"
    db_path:  Path = data_dir / "modelzoo.db"

    # ── Search ────────────────────────────────────────────────────────
    search_max_results: int = 1000

    # ── Sync ──────────────────────────────────────────────────────────
    auto_sync_on_startup: bool = True

    # ── Hugging Face API ──────────────────────────────────────────────
    hf_api_base: str = "https://huggingface.co/api"
    hf_hub_url:  str = "https://huggingface.co"
    hf_token: str | None = None             # Optional: HF_TOKEN env var
    hf_models_per_task: int = 200           # Discovery server pulls more per task

    def ensure_dirs(self) -> None:
        self.data_dir.mkdir(parents=True, exist_ok=True)
        self.logs_dir.mkdir(parents=True, exist_ok=True)


settings = Settings()