Prompt48 commited on
Commit
8a42c37
·
verified ·
1 Parent(s): e9f1721

Upload edit/build_full.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. edit/build_full.py +300 -0
edit/build_full.py ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Build the FULL composition for the complete Mem0_1 tutorial (~752s output).
3
+ Source times -> output times using the segment list from build_cut.py.
4
+ """
5
+ import json, re, sys
6
+ from pathlib import Path
7
+
8
+ TRANSCRIPT = Path(r"D:\PromptEngineer48\In-Progress\P11-Editor\edit\transcripts\Mem0_1.json")
9
+ HF_DIR = Path(r"D:\PromptEngineer48\In-Progress\P11-Editor\edit\hf")
10
+ SKILL = Path(r"C:\Users\palas\.claude\skills\screencast-hype")
11
+
12
+ sys.path.insert(0, str(SKILL / "scripts"))
13
+ from captions_html import build_captions
14
+
15
+ # ---- same segment list as build_cut.py ----
16
+ THRESHOLD = 0.30
17
+ PAD = 0.08
18
+ FILLERS = {"uh", "um"}
19
+ VIDEO_DUR = 805.5
20
+
21
+ data = json.load(open(TRANSCRIPT, encoding="utf-8"))
22
+ words = [w for w in data["words"] if w.get("type") == "word"]
23
+ clean = [w for w in words if w["text"].strip().lower().rstrip(",.") not in FILLERS]
24
+
25
+ segs = []
26
+ s = e = None
27
+ for w in clean:
28
+ if s is None:
29
+ s, e = w["start"], w["end"]
30
+ elif w["start"] - e <= THRESHOLD:
31
+ e = w["end"]
32
+ else:
33
+ segs.append((max(0, s - PAD), e + PAD))
34
+ s, e = w["start"], w["end"]
35
+ if s is not None:
36
+ segs.append((max(0, s - PAD), e + PAD))
37
+
38
+ clamped = []
39
+ for a, b in segs:
40
+ a = round(max(0.0, a), 4)
41
+ b = round(min(VIDEO_DUR, b), 4)
42
+ if clamped and a < clamped[-1][1]:
43
+ a = clamped[-1][1]
44
+ if b > a:
45
+ clamped.append((a, b))
46
+ segs = clamped
47
+
48
+ def src_to_out(src_t):
49
+ out_offset = 0.0
50
+ for (a, b) in segs:
51
+ if src_t <= a:
52
+ return out_offset
53
+ if src_t <= b:
54
+ return out_offset + (src_t - a)
55
+ out_offset += (b - a)
56
+ return out_offset
57
+
58
+ # ---- full video duration ----
59
+ # Segment sum (~730s) is speech-only; actual base_cut.mp4 is 752.5s due to trailing content.
60
+ # Use actual file duration for data-duration so the video plays to completion.
61
+ TOTAL_DUR = 752.5
62
+ print(f"Total output duration: {TOTAL_DUR:.1f}s = {TOTAL_DUR/60:.1f}min")
63
+
64
+ # ---- timing constants ----
65
+ T_TITLE_IN = 1.0
66
+ T_TITLE_OUT = 9.0
67
+ T_CHIP_IN = src_to_out(15.0)
68
+ T_CHIP_OUT = T_CHIP_IN + 8.0
69
+
70
+ # ---- chapter section cards ----
71
+ # Output times calibrated from base_cut.mp4 spot-checks:
72
+ # 95s: Mem0 slides ("THE FIX") 234s: file explorer / chapters ready
73
+ # 305s: MCP JSON setup 362s: /mcp 11 tools visible
74
+ # 410s: "ready to add memories" 478s: Jon Snow memory graph
75
+ # 632s: Jon Snow answering 711s: dashboard / wrap-up
76
+ CARD_DUR = 4.0
77
+ # (output_time, card_id, eyebrow_text, headline_html)
78
+ sec_out = [
79
+ (95.0, "sec1", "UNIVERSAL MEMORY LAYER", "How It <span>Works</span>"),
80
+ (234.0, "sec2", "MEM0.AI · FREE TIER", "Account<br><span>Setup</span>"),
81
+ (305.0, "sec3", "CLAUDE CODE MCP", "Wiring<br><span>Mem0 In</span>"),
82
+ (362.0, "sec4", "11 TOOLS AVAILABLE", "MCP<br><span>Connected</span>"),
83
+ (410.0, "sec5", "29 JON SNOW CHAPTERS", "Ingesting<br><span>Memories</span>"),
84
+ (478.0, "sec6", "GRAPH + VECTOR STORE", "Memories<br><span>Stored</span>"),
85
+ (632.0, "sec7", "THE MOMENT OF TRUTH", "Ask<br><span>Jon Snow</span>"),
86
+ (711.0, "sec8", "MEM0 + CLAUDE CODE", "Ship It<br><span>Anywhere</span>"),
87
+ ]
88
+
89
+ print("\nChapter card output times:")
90
+ for t_out, cid, eyebrow, _ in sec_out:
91
+ print(f" {cid}: {t_out:.1f}s — {eyebrow}")
92
+
93
+ # Sanity: warn if any two cards overlap
94
+ for i in range(len(sec_out) - 1):
95
+ t_end_i = sec_out[i][0] + CARD_DUR
96
+ t_start_next = sec_out[i+1][0]
97
+ if t_end_i > t_start_next:
98
+ print(f" WARNING: {sec_out[i][1]} ends {t_end_i:.1f}s, {sec_out[i+1][1]} starts {t_start_next:.1f}s — overlap!")
99
+
100
+ # ---- captions (full video) ----
101
+ raw_divs, raw_tweens = build_captions(words, start=0.0, end=VIDEO_DUR, per=2, map_time=src_to_out)
102
+
103
+ def filter_tweens_title(tweens_str):
104
+ """Suppress individual caption tweens that fire during the title card window only."""
105
+ lines = tweens_str.split("\n")
106
+ out, skip = [], False
107
+ for line in lines:
108
+ m = re.search(r',(\d+\.\d+)\);$', line)
109
+ t_val = float(m.group(1)) if m else None
110
+ if t_val is not None and T_TITLE_IN <= t_val <= T_TITLE_OUT:
111
+ skip = True
112
+ continue
113
+ if skip and "opacity:0" in line:
114
+ skip = False
115
+ continue
116
+ skip = False
117
+ out.append(line)
118
+ return "\n".join(out)
119
+
120
+ def inject_set_resets(tweens_str):
121
+ """Inject tl.set('.cap',{opacity:0}) 1ms before every caption entry to prevent overlap."""
122
+ lines = tweens_str.split("\n ")
123
+ result = []
124
+ for line in lines:
125
+ if line.strip().startswith("tl.fromTo("):
126
+ m = re.search(r',(\d+\.\d+)\);$', line)
127
+ if m:
128
+ t = float(m.group(1))
129
+ result.append(f'tl.set(".cap",{{opacity:0}},{max(t-0.001,0):.3f});')
130
+ result.append(line)
131
+ return "\n ".join(result)
132
+
133
+ cap_tweens = inject_set_resets(filter_tweens_title(raw_tweens))
134
+
135
+ # ---- build section card HTML divs ----
136
+ sec_div_lines = []
137
+ for _, cid, eyebrow, headline in sec_out:
138
+ sec_div_lines.append(f""" <div id="{cid}" class="glass sec-card">
139
+ <div class="eyebrow">{eyebrow}</div>
140
+ <div class="headline">{headline}</div>
141
+ </div>""")
142
+ sec_divs = "\n".join(sec_div_lines)
143
+
144
+ # ---- build section card GSAP tweens ----
145
+ sec_tween_lines = []
146
+ for t_in, cid, _, _ in sorted(sec_out, key=lambda x: x[0]):
147
+ t_out = t_in + CARD_DUR
148
+ sec_tween_lines += [
149
+ f' tl.set("#{cid}", {{ xPercent: -50, yPercent: -50 }}, 0);',
150
+ f' tl.fromTo("#{cid}",',
151
+ f' {{ opacity: 0, scale: 0.88, filter: "blur(10px)" }},',
152
+ f' {{ opacity: 1, scale: 1, filter: "blur(0px)", duration: 0.4, ease: "power3.out" }},',
153
+ f' {t_in:.2f});',
154
+ f' tl.to("#{cid}", {{ opacity: 0, scale: 0.96, y: -14, duration: 0.3, ease: "power2.in" }}, {t_out:.2f});',
155
+ ]
156
+ sec_card_tweens = "\n".join(sec_tween_lines)
157
+
158
+ # ---- cap-group blackout tweens for section cards ----
159
+ # Title card blackout is handled inline in main JS block.
160
+ # For each section card: hide cap-group in, clear individual caps on restore, show cap-group out.
161
+ cg_lines = []
162
+ for t_in, cid, _, _ in sec_out:
163
+ t_out = t_in + CARD_DUR
164
+ cg_lines += [
165
+ f' tl.to("#cap-group", {{ opacity: 0, duration: 0.05 }}, {t_in:.2f});',
166
+ f' tl.set(".cap", {{ opacity: 0 }}, {t_out - 0.001:.3f});',
167
+ f' tl.to("#cap-group", {{ opacity: 1, duration: 0.05 }}, {t_out:.2f});',
168
+ ]
169
+ cap_group_sec_tweens = "\n".join(cg_lines)
170
+
171
+ # ---- SFX tracks for section card swooshes ----
172
+ # Tracks 0-5: bg video, voice, riser, impact, whoosh_intro, pop_chip
173
+ # Tracks 6+: one per section card whoosh
174
+ sfx_sec_lines = []
175
+ for i, (t_in, cid, _, _) in enumerate(sec_out):
176
+ sfx_t = max(0.0, t_in - 0.15)
177
+ sfx_sec_lines.append(
178
+ f' <audio id="sfx_sec{i}" src="../assets/sfx/whoosh.mp3" '
179
+ f'data-start="{sfx_t:.2f}" data-track-index="{6+i}" data-volume="0.45"></audio>'
180
+ )
181
+ sfx_sec_html = "\n".join(sfx_sec_lines)
182
+
183
+ # ---- generate HTML ----
184
+ html = f"""<!doctype html><html lang="en"><head><meta charset="utf-8"/>
185
+ <style>@font-face{{font-family:"Inter";font-weight:100 900;font-style:normal;src:url("capture/assets/fonts/Inter.woff2") format("woff2");}}</style>
186
+ <style>
187
+ *{{margin:0;padding:0;box-sizing:border-box;}}
188
+ #root{{position:relative;width:1920px;height:1080px;overflow:hidden;background:#0B0F14;font-family:"Inter",sans-serif;}}
189
+ .zoom-wrap{{position:absolute;inset:0;z-index:0;transform-origin:50% 45%;}}
190
+ .zoom-wrap video{{width:1920px;height:1080px;object-fit:cover;display:block;}}
191
+ .glass{{
192
+ background:rgba(255,255,255,0.07);
193
+ backdrop-filter:blur(22px) saturate(130%);
194
+ -webkit-backdrop-filter:blur(22px) saturate(130%);
195
+ border:1px solid rgba(255,255,255,0.18);
196
+ border-radius:26px;
197
+ box-shadow:0 24px 60px rgba(0,0,0,0.45);
198
+ }}
199
+ #title-card{{position:absolute;left:50%;top:42%;z-index:20;opacity:0;padding:52px 72px 56px;text-align:center;min-width:860px;}}
200
+ #title-card .eyebrow{{font-size:22px;font-weight:700;letter-spacing:5px;color:#22D3EE;text-transform:uppercase;margin-bottom:18px;}}
201
+ #title-card .headline{{font-size:76px;font-weight:900;color:#fff;line-height:1.05;}}
202
+ #title-card .headline span{{color:#22D3EE;}}
203
+ #underline{{display:block;height:4px;background:#22D3EE;border-radius:2px;width:0;margin:20px auto 0;box-shadow:0 0 16px #22D3EE99;}}
204
+ #subtitle{{font-size:28px;font-weight:600;color:#9AA7B4;margin-top:14px;opacity:0;}}
205
+ .sec-card{{position:absolute;left:50%;top:38%;z-index:20;opacity:0;padding:28px 52px 32px;text-align:center;min-width:540px;}}
206
+ .sec-card .eyebrow{{font-size:16px;font-weight:700;letter-spacing:4px;color:#22D3EE;text-transform:uppercase;margin-bottom:10px;}}
207
+ .sec-card .headline{{font-size:58px;font-weight:900;color:#fff;line-height:1.05;}}
208
+ .sec-card .headline span{{color:#22D3EE;}}
209
+ #chip1{{position:absolute;left:50%;top:72%;z-index:25;opacity:0;padding:14px 32px;display:flex;align-items:center;gap:12px;}}
210
+ #chip1 .dot{{width:10px;height:10px;border-radius:50%;background:#22D3EE;box-shadow:0 0 10px #22D3EE;}}
211
+ #chip1 .label{{font-size:26px;font-weight:800;color:#fff;letter-spacing:1px;}}
212
+ #chip1 .val{{font-size:26px;font-weight:700;color:#22D3EE;}}
213
+ .cap{{position:absolute;left:50%;bottom:52px;z-index:1;opacity:0;
214
+ font-weight:900;font-size:54px;letter-spacing:1px;color:#fff;white-space:nowrap;
215
+ background:rgba(0,0,0,0.55);padding:8px 28px;border-radius:10px;
216
+ text-shadow:0 2px 8px rgba(0,0,0,.9);}}
217
+ </style></head><body>
218
+ <div id="root" data-composition-id="root" data-width="1920" data-height="1080" data-start="0" data-duration="{TOTAL_DUR}">
219
+ <div class="zoom-wrap" id="zoom">
220
+ <video id="bg" src="base_cut.mp4" data-start="0" data-duration="{TOTAL_DUR}" data-track-index="0" muted playsinline></video>
221
+ </div>
222
+ <audio id="voice" src="base_cut.mp4" data-start="0" data-duration="{TOTAL_DUR}" data-track-index="1" data-volume="1"></audio>
223
+ <audio id="sfx_riser" src="../assets/sfx/riser.mp3" data-start="0.3" data-track-index="2" data-volume="0.7"></audio>
224
+ <audio id="sfx_impact" src="../assets/sfx/impact.mp3" data-start="{T_TITLE_IN:.1f}" data-track-index="3" data-volume="0.65"></audio>
225
+ <audio id="sfx_whoosh" src="../assets/sfx/whoosh.mp3" data-start="{T_TITLE_OUT - 0.1:.1f}" data-track-index="4" data-volume="0.55"></audio>
226
+ <audio id="sfx_pop" src="../assets/sfx/pop.mp3" data-start="{T_CHIP_IN:.1f}" data-track-index="5" data-volume="0.6"></audio>
227
+ {sfx_sec_html}
228
+
229
+ <div id="title-card" class="glass">
230
+ <div class="eyebrow">Mem0 &mdash; Universal Memory Layer</div>
231
+ <div class="headline">Give Your <span>AI Agent</span><br>Persistent Memory</div>
232
+ <span id="underline"></span>
233
+ <div id="subtitle">56K+ GitHub Stars &bull; Free Tier Available</div>
234
+ </div>
235
+
236
+ {sec_divs}
237
+
238
+ <div id="chip1" class="glass">
239
+ <div class="dot"></div>
240
+ <div class="label">WHY AGENTS FORGET&nbsp;&nbsp;</div>
241
+ <div class="val">The Problem</div>
242
+ </div>
243
+
244
+ <div id="cap-group" style="position:absolute;inset:0;z-index:30;pointer-events:none;">
245
+ {raw_divs}
246
+ </div>
247
+
248
+ <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
249
+ <script>
250
+ window.__timelines = window.__timelines || {{}};
251
+ const tl = gsap.timeline({{ paused: true }});
252
+
253
+ tl.set("#zoom", {{ scale: 1.06, transformOrigin: "50% 45%" }}, 0);
254
+ tl.to("#zoom", {{ scale: 1.12, duration: {TOTAL_DUR}, ease: "sine.inOut" }}, 0);
255
+
256
+ // Title card cap-group blackout
257
+ tl.to("#cap-group", {{ opacity: 0, duration: 0.05 }}, {T_TITLE_IN:.2f});
258
+ tl.to("#cap-group", {{ opacity: 1, duration: 0.05 }}, {T_TITLE_OUT:.2f});
259
+
260
+ // Section card cap-group blackouts
261
+ {cap_group_sec_tweens}
262
+
263
+ // Title card
264
+ tl.set("#title-card", {{ xPercent: -50, yPercent: -50 }}, 0);
265
+ tl.fromTo("#title-card",
266
+ {{ opacity: 0, scale: 0.88, filter: "blur(14px)" }},
267
+ {{ opacity: 1, scale: 1, filter: "blur(0px)", duration: 0.6, ease: "power3.out" }},
268
+ {T_TITLE_IN:.1f});
269
+ tl.to("#underline", {{ width: 560, duration: 0.5, ease: "power2.out" }}, {T_TITLE_IN + 0.4:.1f});
270
+ tl.fromTo("#subtitle",
271
+ {{ opacity: 0, y: 18 }},
272
+ {{ opacity: 1, y: 0, duration: 0.45, ease: "power2.out" }},
273
+ {T_TITLE_IN + 0.7:.1f});
274
+ tl.to("#title-card", {{ opacity: 0, scale: 0.96, y: -24, duration: 0.4, ease: "power2.in" }}, {T_TITLE_OUT:.1f});
275
+
276
+ // Chip
277
+ tl.set("#chip1", {{ xPercent: -50 }}, 0);
278
+ tl.fromTo("#chip1",
279
+ {{ opacity: 0, scale: 0.85, y: 20 }},
280
+ {{ opacity: 1, scale: 1, y: 0, duration: 0.45, ease: "back.out(1.7)" }},
281
+ {T_CHIP_IN:.1f});
282
+ tl.to("#chip1", {{ opacity: 0, duration: 0.3, ease: "power2.in" }}, {T_CHIP_OUT:.1f});
283
+
284
+ // Section cards
285
+ {sec_card_tweens}
286
+
287
+ // Captions
288
+ {cap_tweens}
289
+
290
+ window.__timelines["root"] = tl;
291
+ </script>
292
+ </div>
293
+ </body></html>
294
+ """
295
+
296
+ out = HF_DIR / "index.html"
297
+ out.write_text(html, encoding="utf-8")
298
+ print(f"\nWritten: {out}")
299
+ print(f"Caption chunks: {raw_divs.count('<div class=')}")
300
+ print(f"Section cards: {len(sec_out)}")