2b-studio / studio /registry.py
2Btainment's picture
2B-Studio: DAW-Studio, neue Modelle (YuE2, TangoFlux, AudioGen, AudioLDM2), Lizenz-Badges, HF-Login, Einswarm Schwarz/Gold
c600f78 verified
Raw History Blame Contribute Delete
2.25 kB
from __future__ import annotations
from pathlib import Path
from typing import Any
import yaml
from pydantic import BaseModel, Field
DEFAULT_REGISTRY_PATH = Path(__file__).resolve().parents[1] / "schemas" / "model-registry.yaml"
class ModelEntry(BaseModel):
id: str
group: str
label: str
adapter: str
host: str
weights: str | None = None
space_ref: str | None = None
profile: str | None = None
capabilities: dict[str, Any] = Field(default_factory=dict)
blockers: list[str] = Field(default_factory=list)
license: str | None = None
license_badge: str = "check" # free | revenue | nc | check
mvp: bool | str = False
@property
def license_badge_label(self) -> str:
return {"free": "frei", "revenue": "Umsatzgrenze", "nc": "nicht kommerziell"}.get(self.license_badge, "Lizenz prüfen")
@property
def max_duration_s(self) -> int:
return int(self.capabilities.get("max_duration_s", 30))
@property
def supports_vocals(self) -> bool:
return bool(self.capabilities.get("vocals", False))
@property
def supports_lyrics(self) -> bool:
return bool(self.capabilities.get("lyrics", False))
@property
def route_label(self) -> str:
if self.group == "minimax":
return "MiniMax Adapter"
if self.group == "2b-audio":
return "2B-Audio Adapter"
return f"Free Adapter · {self.adapter}"
class ModelRegistry(BaseModel):
version: int
models: list[ModelEntry]
def get(self, model_id: str) -> ModelEntry:
model = next((item for item in self.models if item.id == model_id), None)
if model is None:
raise KeyError(f"Unbekanntes Modell: {model_id}")
return model
def choices(self) -> list[tuple[str, str]]:
return [(model.label, model.id) for model in self.models]
def load_registry(path: Path | None = None) -> ModelRegistry:
registry_path = path or DEFAULT_REGISTRY_PATH
with registry_path.open(encoding="utf-8") as handle:
raw = yaml.safe_load(handle)
if not isinstance(raw, dict):
raise ValueError("Die Model-Registry muss ein YAML-Objekt enthalten.")
return ModelRegistry.model_validate(raw)