| from __future__ import annotations |
|
|
| import json |
| from functools import lru_cache |
| from pathlib import Path |
|
|
| CATALOG_PATH = Path(__file__).with_name("model_catalog.json") |
|
|
|
|
| @lru_cache(maxsize=1) |
| def load_catalog() -> dict[str, dict]: |
| data = json.loads(CATALOG_PATH.read_text(encoding="utf-8")) |
| return {item["id"]: item for item in data["models"]} |
|
|
|
|
| def catalog_choices() -> list[tuple[str, str]]: |
| items = load_catalog().values() |
| return [ |
| (f'{item["category"]} — {item["name"]}', item["id"]) |
| for item in items |
| ] |
|
|
|
|
| def default_model_id() -> str: |
| preferred = "model_bs_roformer_ep_317_sdr_12.9755.ckpt" |
| for item in load_catalog().values(): |
| if item["model_filename"] == preferred: |
| return item["id"] |
| return next(iter(load_catalog())) |
|
|