# Builds MultiShotMaster + LongLive inputs from the verified ShotStream prompt index (same prompts, re-verified here). import csv, hashlib, json, os idx = json.load(open(os.path.expanduser("~/shotstream_run/inputs/prompts_index.json"))) root = os.path.expanduser("~/shotstream_run/prompt_data/storymem_inputs") ids = [l.strip() for l in open(f"{root}/priority_200.ids.txt") if l.strip()] assert len(ids) == 200 and [idx[e]["priority"] for e in ids] == list(range(1, 201)) # independent re-derivation from source files (not trusting the index) for pr, eid in enumerate(ids, 1): sm = json.load(open(f"{root}/episodes/{eid}/shot_mapping.json")); ss = json.load(open(f"{root}/episodes/{eid}/story_script.json")) for i, s in enumerate(sm["shots"], 1): sc = [x for x in ss["scenes"] if x["scene_num"] == s["storymem_scene_num"]]; assert len(sc) == 1 p = sc[0]["video_prompts"][s["storymem_shot_num"] - 1] assert s["shot_id"] == f"Shot{i}" and hashlib.sha256(p.encode()).hexdigest() == s["prompt_sha256"] == idx[eid]["shots"][i-1]["sha256"] assert idx[eid]["shots"][i-1]["prompt"] == p # ---- MultiShotMaster: 75 frames/shot, whole episode in one pass (user decision), keys shot0..shot{n-1} M = os.path.expanduser("~/msm_run/inputs"); rows = [] for eid in ids: info = idx[eid]; n = info["shot_count"] d = {"global_caption": ""} for k, s in enumerate(info["shots"]): d[f"shot{k}"] = s["prompt"] # shot0 = Shot1 jp = f"{M}/json/{eid}.json"; json.dump(d, open(jp, "w", encoding="utf-8"), ensure_ascii=False, indent=1) back = json.load(open(jp, encoding="utf-8")) assert all(hashlib.sha256(back[f"shot{k}"].encode()).hexdigest() == info["shots"][k]["sha256"] for k in range(n)) rows.append({"shot_groups": json.dumps([[75*k, 75*(k+1)] for k in range(n)]), "gemini_caption": jp, "episode_id": eid, "priority": info["priority"], "shot_count": n}) cols = ["shot_groups", "gemini_caption", "episode_id", "priority", "shot_count"] def wcsv(p, rs): with open(p, "w", newline="") as f: w = csv.DictWriter(f, fieldnames=cols); w.writeheader(); w.writerows(rs) wcsv(f"{M}/all_200.csv", rows) wcsv(f"{M}/smoke_p7.csv", [r for r in rows if r["priority"] == 7]) # ---- LongLive: one jsonl + config per shot count, priority order inside each L = os.path.expanduser("~/longlive_run/inputs") base = open(os.path.expanduser("~/longlive_run/LongLive/LongLive1.0/configs/longlive_interactive_inference.yaml")).read() for n in (4, 6, 8): sel = [e for e in ids if idx[e]["shot_count"] == n] with open(f"{L}/prompts_{n}shot.jsonl", "w", encoding="utf-8") as f: for e in sel: f.write(json.dumps({"prompts": [s["prompt"] for s in idx[e]["shots"]], "episode_id": e}, ensure_ascii=False) + "\n") cfg = base for old, new in [("data_path: longlive_models/prompts/interactive_example.jsonl", f"data_path: {L}/prompts_{n}shot.jsonl"), ("output_folder: videos/interactive", f"output_folder: {os.path.expanduser('~/longlive_run/outputs')}"), ("num_output_frames: 240", f"num_output_frames: {21*n}"), ("switch_frame_indices: 40, 80, 120, 160, 200", "switch_frame_indices: " + ", ".join(str(21*k) for k in range(1, n)))]: assert cfg.count(old) == 1; cfg = cfg.replace(old, new) open(f"{L}/longlive_{n}shot.yaml", "w").write(cfg) print(n, "shots:", len(sel), "first:", sel[0], idx[sel[0]]["priority"]) print("msm rows", len(rows))