radio: read a director script file (was stale on the hub)
Browse files- kaggle/radio_demo.py +15 -1
kaggle/radio_demo.py
CHANGED
|
@@ -38,6 +38,10 @@ GAP_S = 0.7
|
|
| 38 |
SR = 44100
|
| 39 |
|
| 40 |
SCRIPT_LLM = os.environ.get("SCRIPT_LLM", "Qwen/Qwen2.5-1.5B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
CAST = {"叙述": "a08", "故事": "a08", "耳语": "a09", "开场": "a05", "收尾": "a08"}
|
| 42 |
|
| 43 |
FALLBACK = [
|
|
@@ -64,6 +68,16 @@ def patch_fp32() -> None:
|
|
| 64 |
p.write_text(s)
|
| 65 |
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
def write_script() -> tuple[list[dict], str]:
|
| 68 |
"""Ask a small instruct model for the segment; fall back to a fixed script."""
|
| 69 |
import torch
|
|
@@ -143,7 +157,7 @@ def main() -> None:
|
|
| 143 |
(OUT / "lines").mkdir(parents=True, exist_ok=True)
|
| 144 |
torch.manual_seed(SEED)
|
| 145 |
|
| 146 |
-
plan, source = write_script()
|
| 147 |
lines = cast(plan)
|
| 148 |
(OUT / "script.json").write_text(json.dumps({"source": source, "lines": lines},
|
| 149 |
ensure_ascii=False, indent=1))
|
|
|
|
| 38 |
SR = 44100
|
| 39 |
|
| 40 |
SCRIPT_LLM = os.environ.get("SCRIPT_LLM", "Qwen/Qwen2.5-1.5B-Instruct")
|
| 41 |
+
# A file written by the director stage. Set this to skip the in-process LLM:
|
| 42 |
+
# Qwen3.5 needs transformers 5.x, Ming needs 4.46.3, so they cannot share a
|
| 43 |
+
# process and the script has to arrive as a file.
|
| 44 |
+
SCRIPT_FILE = os.environ.get("SCRIPT_FILE", "")
|
| 45 |
CAST = {"叙述": "a08", "故事": "a08", "耳语": "a09", "开场": "a05", "收尾": "a08"}
|
| 46 |
|
| 47 |
FALLBACK = [
|
|
|
|
| 68 |
p.write_text(s)
|
| 69 |
|
| 70 |
|
| 71 |
+
def load_script(path: str) -> tuple[list[dict], str]:
|
| 72 |
+
"""Read a script the director stage already validated."""
|
| 73 |
+
doc = json.loads(Path(path).read_text())
|
| 74 |
+
rows = doc.get("lines") or doc
|
| 75 |
+
rows = [r for r in rows if isinstance(r, dict) and r.get("text")]
|
| 76 |
+
if len(rows) < 1:
|
| 77 |
+
raise ValueError(f"{path} has no usable lines")
|
| 78 |
+
return rows, f"director:{doc.get('model', 'file')}"
|
| 79 |
+
|
| 80 |
+
|
| 81 |
def write_script() -> tuple[list[dict], str]:
|
| 82 |
"""Ask a small instruct model for the segment; fall back to a fixed script."""
|
| 83 |
import torch
|
|
|
|
| 157 |
(OUT / "lines").mkdir(parents=True, exist_ok=True)
|
| 158 |
torch.manual_seed(SEED)
|
| 159 |
|
| 160 |
+
plan, source = (load_script(SCRIPT_FILE) if SCRIPT_FILE else write_script())
|
| 161 |
lines = cast(plan)
|
| 162 |
(OUT / "script.json").write_text(json.dumps({"source": source, "lines": lines},
|
| 163 |
ensure_ascii=False, indent=1))
|