cajpany's picture
Upload folder using huggingface_hub
6031840 verified
Raw
History Blame Contribute Delete
2.05 kB
"""Pre-rendered showcase broadcasts."""
from __future__ import annotations
import json
from dataclasses import dataclass
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
SHOWCASE_DIR = ROOT / "assets" / "showcases"
@dataclass(frozen=True)
class Showcase:
id: str
label: str
audio_path: Path
script_path: Path
SHOWCASES = [
Showcase(
id="phone_booth",
label="The Case of A Phone Booth That Rings Under",
audio_path=SHOWCASE_DIR / "the-case-of-a-phone-booth-that-rings-under.crude.wav",
script_path=SHOWCASE_DIR / "the-case-of-a-phone-booth-that-rings-under.json",
),
Showcase(
id="lighthouse",
label="The Case of Two Rival Lighthouse Keepers One Light",
audio_path=SHOWCASE_DIR / "the-case-of-two-rival-lighthouse-keepers-one-light.crude.wav",
script_path=SHOWCASE_DIR / "the-case-of-two-rival-lighthouse-keepers-one-light.json",
),
Showcase(
id="wrong_bride",
label="The Case of A Wedding Where Every Guest Recognizes",
audio_path=SHOWCASE_DIR / "the-case-of-a-wedding-where-every-guest-recognizes.crude.wav",
script_path=SHOWCASE_DIR / "the-case-of-a-wedding-where-every-guest-recognizes.json",
),
]
def default_showcase() -> tuple[str | None, str]:
"""Return the default showcase audio path and pretty script JSON."""
return load_showcase(SHOWCASES[0].label)
def showcase_labels() -> list[str]:
return [showcase.label for showcase in SHOWCASES]
def load_showcase(label: str) -> tuple[str | None, str]:
showcase = _find_showcase(label)
if showcase is None or not showcase.audio_path.exists() or not showcase.script_path.exists():
return None, "{}"
payload = json.loads(showcase.script_path.read_text(encoding="utf-8"))
return str(showcase.audio_path), json.dumps(payload, indent=2)
def _find_showcase(label: str) -> Showcase | None:
for showcase in SHOWCASES:
if showcase.label == label:
return showcase
return None