"""Resolve private model assets locally or through an authenticated HF repo.""" import os import tempfile from pathlib import Path import yaml APP_DIR = Path(__file__).resolve().parent PRIVATE_ASSET_REPO = os.environ.get("POCKET_TTS_ASSET_REPO", "Brakanier/pocket-tts-ru-private") PRIVATE_ASSET_REVISION = os.environ.get( "POCKET_TTS_ASSET_REVISION", "03f4c178cfef1ee0cefe4c6cec0372e5dd258842" ) def private_asset_uri(relative_path: str) -> str: return f"hf://{PRIVATE_ASSET_REPO}/{relative_path}@{PRIVATE_ASSET_REVISION}" def resolve_private_asset(relative_path: str) -> Path | str: """Prefer a local development asset; use the private Hub repo in the Space.""" local_path = APP_DIR / relative_path if local_path.is_file(): return local_path return private_asset_uri(relative_path) def build_runtime_model_config(template_path: Path) -> Path: """Write an ephemeral config with absolute local paths or private HF URIs.""" with template_path.open(encoding="utf-8") as stream: config = yaml.safe_load(stream) config["weights_path"] = str(resolve_private_asset("model/model.safetensors")) config["flow_lm"]["lookup_table"]["tokenizer_path"] = str( resolve_private_asset("model/tokenizer.model") ) runtime_path = Path(tempfile.gettempdir()) / "pocket_tts_ru_runtime_config.yaml" with runtime_path.open("w", encoding="utf-8") as stream: yaml.safe_dump(config, stream, allow_unicode=True, sort_keys=False) return runtime_path