Spaces:
Sleeping
Add browser-based review/edit step
Browse filesNew format=review (now the default) returns a self-contained HTML page
with inline images, an editor toolbar, and per-segment controls for
section title, alt text, narration, OCR text, and an include toggle.
The editor is fully client-side: edits stay in the DOM, "Save edits"
exports a JSON metadata file (per-segment section_title, alt_text,
narration, ocr_text, include), "Load edits" reapplies a saved file, and
"Download final HTML" snapshots a clean copy with editor chrome stripped,
excluded segments removed, and the TOC renumbered.
Inspired by the two-pass JSON workflow in maryjoanz/video_to_studyguide,
but with the review step inlined into the browser so the metadata file
is optional rather than a required intermediate.
https://claude.ai/code/session_01G3XpEehfr9DnX9L7BahQ4L
- app/main.py +7 -1
- app/pipeline/__init__.py +3 -1
- app/pipeline/html_gen.py +32 -8
- app/templates/index.html +7 -1
- app/templates/review.html +477 -0
- tests/test_html_gen.py +49 -0
|
@@ -19,6 +19,7 @@ from .pipeline import (
|
|
| 19 |
ocr_frame,
|
| 20 |
parse_transcript,
|
| 21 |
render_guide,
|
|
|
|
| 22 |
)
|
| 23 |
from .pipeline.html_gen import build_segments
|
| 24 |
|
|
@@ -46,7 +47,7 @@ async def process(
|
|
| 46 |
title: str = Form(...),
|
| 47 |
video: UploadFile = File(...),
|
| 48 |
transcript: UploadFile = File(...),
|
| 49 |
-
format: str = Form("
|
| 50 |
threshold: float = Form(27.0),
|
| 51 |
face_threshold: float = Form(0.12),
|
| 52 |
lang: str = Form("en"),
|
|
@@ -94,6 +95,11 @@ async def process(
|
|
| 94 |
log.info("Running OCR on %d frames", len(kept))
|
| 95 |
ocr_texts = [ocr_frame(f.image_path) for f in kept]
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
inline = format == "single"
|
| 98 |
segments = build_segments(kept, narrations, ocr_texts, inline_images=inline)
|
| 99 |
html = render_guide(title, segments, lang=lang, inline_images=inline)
|
|
|
|
| 19 |
ocr_frame,
|
| 20 |
parse_transcript,
|
| 21 |
render_guide,
|
| 22 |
+
render_review,
|
| 23 |
)
|
| 24 |
from .pipeline.html_gen import build_segments
|
| 25 |
|
|
|
|
| 47 |
title: str = Form(...),
|
| 48 |
video: UploadFile = File(...),
|
| 49 |
transcript: UploadFile = File(...),
|
| 50 |
+
format: str = Form("review"),
|
| 51 |
threshold: float = Form(27.0),
|
| 52 |
face_threshold: float = Form(0.12),
|
| 53 |
lang: str = Form("en"),
|
|
|
|
| 95 |
log.info("Running OCR on %d frames", len(kept))
|
| 96 |
ocr_texts = [ocr_frame(f.image_path) for f in kept]
|
| 97 |
|
| 98 |
+
if format == "review":
|
| 99 |
+
segments = build_segments(kept, narrations, ocr_texts, inline_images=True)
|
| 100 |
+
html = render_review(title, segments, lang=lang)
|
| 101 |
+
return Response(content=html, media_type="text/html; charset=utf-8")
|
| 102 |
+
|
| 103 |
inline = format == "single"
|
| 104 |
segments = build_segments(kept, narrations, ocr_texts, inline_images=inline)
|
| 105 |
html = render_guide(title, segments, lang=lang, inline_images=inline)
|
|
@@ -19,6 +19,7 @@ __all__ = [
|
|
| 19 |
"ocr_frame",
|
| 20 |
"Segment",
|
| 21 |
"render_guide",
|
|
|
|
| 22 |
"bundle_zip",
|
| 23 |
]
|
| 24 |
|
|
@@ -33,6 +34,7 @@ _EXPORTS = {
|
|
| 33 |
"ocr_frame": "ocr",
|
| 34 |
"Segment": "html_gen",
|
| 35 |
"render_guide": "html_gen",
|
|
|
|
| 36 |
"bundle_zip": "html_gen",
|
| 37 |
}
|
| 38 |
|
|
@@ -45,7 +47,7 @@ def __getattr__(name: str) -> Any:
|
|
| 45 |
|
| 46 |
|
| 47 |
if TYPE_CHECKING: # pragma: no cover
|
| 48 |
-
from .html_gen import Segment, bundle_zip, render_guide
|
| 49 |
from .ocr import ocr_frame
|
| 50 |
from .filter import filter_instructor_frames, is_instructor_frame
|
| 51 |
from .scenes import SceneFrame, detect_and_extract
|
|
|
|
| 19 |
"ocr_frame",
|
| 20 |
"Segment",
|
| 21 |
"render_guide",
|
| 22 |
+
"render_review",
|
| 23 |
"bundle_zip",
|
| 24 |
]
|
| 25 |
|
|
|
|
| 34 |
"ocr_frame": "ocr",
|
| 35 |
"Segment": "html_gen",
|
| 36 |
"render_guide": "html_gen",
|
| 37 |
+
"render_review": "html_gen",
|
| 38 |
"bundle_zip": "html_gen",
|
| 39 |
}
|
| 40 |
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
if TYPE_CHECKING: # pragma: no cover
|
| 50 |
+
from .html_gen import Segment, bundle_zip, render_guide, render_review # noqa: F401
|
| 51 |
from .ocr import ocr_frame
|
| 52 |
from .filter import filter_instructor_frames, is_instructor_frame
|
| 53 |
from .scenes import SceneFrame, detect_and_extract
|
|
@@ -22,6 +22,7 @@ class Segment:
|
|
| 22 |
narration: str
|
| 23 |
ocr_text: str
|
| 24 |
alt_draft: str
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
def _format_timestamp(seconds: float) -> str:
|
|
@@ -52,6 +53,10 @@ def _image_data_uri(image_path: Path) -> str:
|
|
| 52 |
return f"data:image/{suffix};base64,{b64}"
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def build_segments(
|
| 56 |
frames,
|
| 57 |
narrations: list[str],
|
|
@@ -72,11 +77,23 @@ def build_segments(
|
|
| 72 |
narration=narration,
|
| 73 |
ocr_text=ocr_text,
|
| 74 |
alt_draft=_draft_alt_from_ocr(ocr_text),
|
|
|
|
| 75 |
)
|
| 76 |
)
|
| 77 |
return segments
|
| 78 |
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
def render_guide(
|
| 81 |
title: str,
|
| 82 |
segments: list[Segment],
|
|
@@ -85,14 +102,7 @@ def render_guide(
|
|
| 85 |
inline_images: bool = False,
|
| 86 |
image_dir_name: str = "images",
|
| 87 |
) -> str:
|
| 88 |
-
|
| 89 |
-
loader=FileSystemLoader(TEMPLATES_DIR),
|
| 90 |
-
autoescape=select_autoescape(["html"]),
|
| 91 |
-
trim_blocks=True,
|
| 92 |
-
lstrip_blocks=True,
|
| 93 |
-
)
|
| 94 |
-
env.filters["timestamp"] = _format_timestamp
|
| 95 |
-
template = env.get_template("guide.html")
|
| 96 |
return template.render(
|
| 97 |
title=title,
|
| 98 |
lang=lang,
|
|
@@ -102,6 +112,20 @@ def render_guide(
|
|
| 102 |
)
|
| 103 |
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
def bundle_zip(
|
| 106 |
html: str,
|
| 107 |
frame_image_paths: list[Path],
|
|
|
|
| 22 |
narration: str
|
| 23 |
ocr_text: str
|
| 24 |
alt_draft: str
|
| 25 |
+
section_title: str
|
| 26 |
|
| 27 |
|
| 28 |
def _format_timestamp(seconds: float) -> str:
|
|
|
|
| 53 |
return f"data:image/{suffix};base64,{b64}"
|
| 54 |
|
| 55 |
|
| 56 |
+
def _default_section_title(index: int, start_seconds: float) -> str:
|
| 57 |
+
return f"Segment {index + 1} — {_format_timestamp(start_seconds)}"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
def build_segments(
|
| 61 |
frames,
|
| 62 |
narrations: list[str],
|
|
|
|
| 77 |
narration=narration,
|
| 78 |
ocr_text=ocr_text,
|
| 79 |
alt_draft=_draft_alt_from_ocr(ocr_text),
|
| 80 |
+
section_title=_default_section_title(i, frame.start_seconds),
|
| 81 |
)
|
| 82 |
)
|
| 83 |
return segments
|
| 84 |
|
| 85 |
|
| 86 |
+
def _env() -> Environment:
|
| 87 |
+
env = Environment(
|
| 88 |
+
loader=FileSystemLoader(TEMPLATES_DIR),
|
| 89 |
+
autoescape=select_autoescape(["html"]),
|
| 90 |
+
trim_blocks=True,
|
| 91 |
+
lstrip_blocks=True,
|
| 92 |
+
)
|
| 93 |
+
env.filters["timestamp"] = _format_timestamp
|
| 94 |
+
return env
|
| 95 |
+
|
| 96 |
+
|
| 97 |
def render_guide(
|
| 98 |
title: str,
|
| 99 |
segments: list[Segment],
|
|
|
|
| 102 |
inline_images: bool = False,
|
| 103 |
image_dir_name: str = "images",
|
| 104 |
) -> str:
|
| 105 |
+
template = _env().get_template("guide.html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
return template.render(
|
| 107 |
title=title,
|
| 108 |
lang=lang,
|
|
|
|
| 112 |
)
|
| 113 |
|
| 114 |
|
| 115 |
+
def render_review(
|
| 116 |
+
title: str,
|
| 117 |
+
segments: list[Segment],
|
| 118 |
+
*,
|
| 119 |
+
lang: str = "en",
|
| 120 |
+
) -> str:
|
| 121 |
+
"""Render an in-browser editor page. Images must be inlined as data URIs
|
| 122 |
+
so the page is self-contained — saved/reopened HTML keeps working."""
|
| 123 |
+
if any(seg.image_data_uri is None for seg in segments):
|
| 124 |
+
raise ValueError("render_review requires segments built with inline_images=True")
|
| 125 |
+
template = _env().get_template("review.html")
|
| 126 |
+
return template.render(title=title, lang=lang, segments=segments)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
def bundle_zip(
|
| 130 |
html: str,
|
| 131 |
frame_image_paths: list[Path],
|
|
@@ -38,7 +38,8 @@
|
|
| 38 |
|
| 39 |
<fieldset>
|
| 40 |
<legend>Output format</legend>
|
| 41 |
-
<label><input type="radio" name="format" value="
|
|
|
|
| 42 |
<label><input type="radio" name="format" value="single"> Single self-contained HTML (images inlined)</label>
|
| 43 |
</fieldset>
|
| 44 |
|
|
@@ -67,6 +68,11 @@
|
|
| 67 |
<li>Aligns transcript narration to each visual segment.</li>
|
| 68 |
<li>Produces a WCAG 2.2 AA-ready HTML document with draft alt-text flagged for human review.</li>
|
| 69 |
</ol>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
</section>
|
| 71 |
</main>
|
| 72 |
</body>
|
|
|
|
| 38 |
|
| 39 |
<fieldset>
|
| 40 |
<legend>Output format</legend>
|
| 41 |
+
<label><input type="radio" name="format" value="review" checked> Review & edit in browser (recommended)</label>
|
| 42 |
+
<label><input type="radio" name="format" value="zip"> Zip bundle (HTML + images folder)</label>
|
| 43 |
<label><input type="radio" name="format" value="single"> Single self-contained HTML (images inlined)</label>
|
| 44 |
</fieldset>
|
| 45 |
|
|
|
|
| 68 |
<li>Aligns transcript narration to each visual segment.</li>
|
| 69 |
<li>Produces a WCAG 2.2 AA-ready HTML document with draft alt-text flagged for human review.</li>
|
| 70 |
</ol>
|
| 71 |
+
<p>
|
| 72 |
+
In <strong>review mode</strong>, the result opens in your browser as an editor: rewrite alt text
|
| 73 |
+
and section titles, edit narration and on-screen text, drop unwanted segments, then download a
|
| 74 |
+
clean final HTML. Edits can be saved and reloaded as JSON.
|
| 75 |
+
</p>
|
| 76 |
</section>
|
| 77 |
</main>
|
| 78 |
</body>
|
|
@@ -0,0 +1,477 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="{{ lang }}" data-vgm-review="1">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>{{ title }}</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--fg: #1a1a1a;
|
| 10 |
+
--bg: #ffffff;
|
| 11 |
+
--muted: #555;
|
| 12 |
+
--accent: #0b4f9c;
|
| 13 |
+
--rule: #d0d4da;
|
| 14 |
+
--warn-bg: #fff8db;
|
| 15 |
+
--warn-fg: #5a4500;
|
| 16 |
+
--edit-bg: #eef4fd;
|
| 17 |
+
--edit-fg: #0b3a72;
|
| 18 |
+
--edit-rule: #b6cdee;
|
| 19 |
+
}
|
| 20 |
+
@media (prefers-color-scheme: dark) {
|
| 21 |
+
:root {
|
| 22 |
+
--fg: #f1f1f1;
|
| 23 |
+
--bg: #121417;
|
| 24 |
+
--muted: #b0b6bd;
|
| 25 |
+
--accent: #7eb6ff;
|
| 26 |
+
--rule: #2a2f36;
|
| 27 |
+
--warn-bg: #3a2f00;
|
| 28 |
+
--warn-fg: #ffe98a;
|
| 29 |
+
--edit-bg: #102136;
|
| 30 |
+
--edit-fg: #cfe1ff;
|
| 31 |
+
--edit-rule: #25446e;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
* { box-sizing: border-box; }
|
| 35 |
+
html { font-size: 18px; }
|
| 36 |
+
body {
|
| 37 |
+
margin: 0;
|
| 38 |
+
color: var(--fg);
|
| 39 |
+
background: var(--bg);
|
| 40 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 41 |
+
line-height: 1.6;
|
| 42 |
+
}
|
| 43 |
+
a.skip-link {
|
| 44 |
+
position: absolute;
|
| 45 |
+
left: -9999px;
|
| 46 |
+
top: 0;
|
| 47 |
+
background: var(--accent);
|
| 48 |
+
color: #fff;
|
| 49 |
+
padding: 0.5rem 1rem;
|
| 50 |
+
z-index: 100;
|
| 51 |
+
}
|
| 52 |
+
a.skip-link:focus { left: 1rem; top: 1rem; }
|
| 53 |
+
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
|
| 54 |
+
header.page-header, main, footer.page-footer {
|
| 55 |
+
max-width: 48rem;
|
| 56 |
+
margin: 0 auto;
|
| 57 |
+
padding: 1.5rem 1.25rem;
|
| 58 |
+
}
|
| 59 |
+
header.page-header { border-bottom: 1px solid var(--rule); padding-top: 5.5rem; }
|
| 60 |
+
h1 { font-size: 1.875rem; margin: 0 0 0.5rem; line-height: 1.25; }
|
| 61 |
+
h2 { font-size: 1.375rem; margin: 0 0 0.5rem; line-height: 1.3; }
|
| 62 |
+
h3 { font-size: 1.05rem; margin: 1rem 0 0.25rem; color: var(--muted); }
|
| 63 |
+
p { margin: 0 0 1rem; }
|
| 64 |
+
.meta { color: var(--muted); font-size: 0.95rem; }
|
| 65 |
+
.alt-warning {
|
| 66 |
+
background: var(--warn-bg);
|
| 67 |
+
color: var(--warn-fg);
|
| 68 |
+
border-left: 4px solid var(--accent);
|
| 69 |
+
padding: 0.75rem 1rem;
|
| 70 |
+
margin: 1rem 0 2rem;
|
| 71 |
+
font-size: 0.95rem;
|
| 72 |
+
}
|
| 73 |
+
article.segment {
|
| 74 |
+
padding: 1.5rem 0;
|
| 75 |
+
border-top: 1px solid var(--rule);
|
| 76 |
+
}
|
| 77 |
+
article.segment:first-of-type { border-top: 0; }
|
| 78 |
+
article.segment[data-included="false"] {
|
| 79 |
+
opacity: 0.4;
|
| 80 |
+
background: repeating-linear-gradient(
|
| 81 |
+
45deg, transparent, transparent 8px,
|
| 82 |
+
rgba(127,127,127,0.06) 8px, rgba(127,127,127,0.06) 16px
|
| 83 |
+
);
|
| 84 |
+
}
|
| 85 |
+
figure { margin: 0 0 1rem; }
|
| 86 |
+
figure img {
|
| 87 |
+
width: 100%;
|
| 88 |
+
height: auto;
|
| 89 |
+
display: block;
|
| 90 |
+
border: 1px solid var(--rule);
|
| 91 |
+
border-radius: 4px;
|
| 92 |
+
}
|
| 93 |
+
figcaption {
|
| 94 |
+
font-size: 0.9rem;
|
| 95 |
+
color: var(--muted);
|
| 96 |
+
margin-top: 0.5rem;
|
| 97 |
+
}
|
| 98 |
+
.ocr {
|
| 99 |
+
font-size: 0.95rem;
|
| 100 |
+
background: rgba(127, 127, 127, 0.08);
|
| 101 |
+
padding: 0.75rem 1rem;
|
| 102 |
+
border-radius: 4px;
|
| 103 |
+
white-space: pre-wrap;
|
| 104 |
+
}
|
| 105 |
+
.ocr summary { cursor: pointer; font-weight: 600; color: var(--accent); }
|
| 106 |
+
.ocr[open] { padding-top: 0.5rem; }
|
| 107 |
+
nav.toc ol { padding-left: 1.25rem; }
|
| 108 |
+
nav.toc a { color: var(--accent); }
|
| 109 |
+
|
| 110 |
+
/* Editor chrome — stripped from downloaded final HTML. */
|
| 111 |
+
.vgm-toolbar {
|
| 112 |
+
position: fixed;
|
| 113 |
+
top: 0; left: 0; right: 0;
|
| 114 |
+
background: var(--edit-bg);
|
| 115 |
+
color: var(--edit-fg);
|
| 116 |
+
border-bottom: 1px solid var(--edit-rule);
|
| 117 |
+
padding: 0.6rem 1rem;
|
| 118 |
+
display: flex;
|
| 119 |
+
gap: 0.5rem;
|
| 120 |
+
align-items: center;
|
| 121 |
+
flex-wrap: wrap;
|
| 122 |
+
z-index: 50;
|
| 123 |
+
font-size: 0.95rem;
|
| 124 |
+
}
|
| 125 |
+
.vgm-toolbar strong { margin-right: 0.5rem; }
|
| 126 |
+
.vgm-toolbar button, .vgm-toolbar label.btn {
|
| 127 |
+
background: var(--accent);
|
| 128 |
+
color: #fff;
|
| 129 |
+
border: 0;
|
| 130 |
+
padding: 0.4rem 0.8rem;
|
| 131 |
+
font-size: 0.9rem;
|
| 132 |
+
border-radius: 4px;
|
| 133 |
+
cursor: pointer;
|
| 134 |
+
}
|
| 135 |
+
.vgm-toolbar button:hover, .vgm-toolbar label.btn:hover { filter: brightness(1.08); }
|
| 136 |
+
.vgm-toolbar input[type="file"] { display: none; }
|
| 137 |
+
.vgm-toolbar .vgm-status {
|
| 138 |
+
margin-left: auto;
|
| 139 |
+
font-size: 0.85rem;
|
| 140 |
+
color: var(--muted);
|
| 141 |
+
}
|
| 142 |
+
[contenteditable="true"] {
|
| 143 |
+
outline: 1px dashed var(--edit-rule);
|
| 144 |
+
outline-offset: 2px;
|
| 145 |
+
padding: 0.1rem 0.3rem;
|
| 146 |
+
border-radius: 3px;
|
| 147 |
+
background: rgba(127,127,127,0.04);
|
| 148 |
+
}
|
| 149 |
+
[contenteditable="true"]:focus {
|
| 150 |
+
outline: 2px solid var(--accent);
|
| 151 |
+
background: rgba(127,127,127,0.08);
|
| 152 |
+
}
|
| 153 |
+
.vgm-edit-panel {
|
| 154 |
+
background: var(--edit-bg);
|
| 155 |
+
color: var(--edit-fg);
|
| 156 |
+
border: 1px solid var(--edit-rule);
|
| 157 |
+
border-radius: 6px;
|
| 158 |
+
padding: 0.75rem 1rem;
|
| 159 |
+
margin-bottom: 1rem;
|
| 160 |
+
display: grid;
|
| 161 |
+
grid-template-columns: 1fr;
|
| 162 |
+
gap: 0.5rem;
|
| 163 |
+
font-size: 0.9rem;
|
| 164 |
+
}
|
| 165 |
+
.vgm-edit-panel label {
|
| 166 |
+
display: flex;
|
| 167 |
+
flex-direction: column;
|
| 168 |
+
gap: 0.25rem;
|
| 169 |
+
font-weight: 600;
|
| 170 |
+
}
|
| 171 |
+
.vgm-edit-panel input[type="text"] {
|
| 172 |
+
width: 100%;
|
| 173 |
+
padding: 0.4rem 0.5rem;
|
| 174 |
+
font-size: 0.95rem;
|
| 175 |
+
border: 1px solid var(--edit-rule);
|
| 176 |
+
border-radius: 4px;
|
| 177 |
+
background: var(--bg);
|
| 178 |
+
color: var(--fg);
|
| 179 |
+
font-weight: normal;
|
| 180 |
+
}
|
| 181 |
+
.vgm-edit-panel .row {
|
| 182 |
+
display: flex;
|
| 183 |
+
align-items: center;
|
| 184 |
+
gap: 0.5rem;
|
| 185 |
+
font-weight: 600;
|
| 186 |
+
}
|
| 187 |
+
.vgm-edit-panel .row input[type="checkbox"] { width: 1.1rem; height: 1.1rem; }
|
| 188 |
+
.vgm-hint { font-size: 0.85rem; color: var(--muted); margin: 0.25rem 0 0; }
|
| 189 |
+
</style>
|
| 190 |
+
</head>
|
| 191 |
+
<body>
|
| 192 |
+
<a class="skip-link" href="#main">Skip to main content</a>
|
| 193 |
+
|
| 194 |
+
<div class="vgm-toolbar" data-editor role="toolbar" aria-label="Study guide editor">
|
| 195 |
+
<strong>Editor</strong>
|
| 196 |
+
<button type="button" data-action="save-json">Save edits (JSON)</button>
|
| 197 |
+
<label class="btn">
|
| 198 |
+
Load edits (JSON)
|
| 199 |
+
<input type="file" accept="application/json,.json" data-action="load-json">
|
| 200 |
+
</label>
|
| 201 |
+
<button type="button" data-action="download-html">Download final HTML</button>
|
| 202 |
+
<span class="vgm-status" role="status" aria-live="polite"></span>
|
| 203 |
+
</div>
|
| 204 |
+
|
| 205 |
+
<header class="page-header" role="banner">
|
| 206 |
+
<h1 contenteditable="true" data-bind="title" spellcheck="true">{{ title }}</h1>
|
| 207 |
+
<p class="meta">Auto-generated study guide. Review and edit each segment, then download the final HTML.</p>
|
| 208 |
+
</header>
|
| 209 |
+
|
| 210 |
+
<main id="main" tabindex="-1">
|
| 211 |
+
<div class="alt-warning" role="note" data-editor>
|
| 212 |
+
<strong>Review checklist:</strong> rewrite each <em>Alt text</em> to convey purpose
|
| 213 |
+
(not raw OCR). Edit section titles, narration, and on-screen text directly. Uncheck
|
| 214 |
+
<em>Include in final guide</em> to drop a segment. Use <em>Save edits</em> to keep your
|
| 215 |
+
work, then <em>Download final HTML</em> when done.
|
| 216 |
+
</div>
|
| 217 |
+
|
| 218 |
+
{% if segments|length > 1 %}
|
| 219 |
+
<nav class="toc" aria-label="Table of contents" data-toc>
|
| 220 |
+
<h2>Contents</h2>
|
| 221 |
+
<ol>
|
| 222 |
+
{% for seg in segments %}
|
| 223 |
+
<li data-toc-item data-toc-for="segment-{{ seg.index }}"><a href="#segment-{{ seg.index }}">{{ seg.section_title }}</a></li>
|
| 224 |
+
{% endfor %}
|
| 225 |
+
</ol>
|
| 226 |
+
</nav>
|
| 227 |
+
{% endif %}
|
| 228 |
+
|
| 229 |
+
{% for seg in segments %}
|
| 230 |
+
<article class="segment"
|
| 231 |
+
id="segment-{{ seg.index }}"
|
| 232 |
+
aria-labelledby="segment-{{ seg.index }}-heading"
|
| 233 |
+
data-segment-index="{{ seg.index }}"
|
| 234 |
+
data-included="true"
|
| 235 |
+
data-start="{{ seg.start_seconds }}"
|
| 236 |
+
data-end="{{ seg.end_seconds }}">
|
| 237 |
+
<div class="vgm-edit-panel" data-editor>
|
| 238 |
+
<label>
|
| 239 |
+
Section title
|
| 240 |
+
<input type="text" data-bind="section_title" value="{{ seg.section_title }}">
|
| 241 |
+
</label>
|
| 242 |
+
<label>
|
| 243 |
+
Alt text (image description)
|
| 244 |
+
<input type="text" data-bind="alt_text" value="{{ seg.alt_draft }}">
|
| 245 |
+
<span class="vgm-hint">Describe the image's purpose for screen-reader users.</span>
|
| 246 |
+
</label>
|
| 247 |
+
<div class="row">
|
| 248 |
+
<input type="checkbox" data-bind="include" id="include-{{ seg.index }}" checked>
|
| 249 |
+
<label for="include-{{ seg.index }}">Include in final guide</label>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
|
| 253 |
+
<h2 id="segment-{{ seg.index }}-heading" data-bind-target="section_title">{{ seg.section_title }}</h2>
|
| 254 |
+
<p class="meta">
|
| 255 |
+
<time datetime="PT{{ seg.start_seconds | int }}S">{{ seg.start_seconds | timestamp }}</time>
|
| 256 |
+
– <time datetime="PT{{ seg.end_seconds | int }}S">{{ seg.end_seconds | timestamp }}</time>
|
| 257 |
+
</p>
|
| 258 |
+
|
| 259 |
+
<figure>
|
| 260 |
+
<img src="{{ seg.image_data_uri }}"
|
| 261 |
+
alt="{{ seg.alt_draft }}"
|
| 262 |
+
data-bind-target="alt_text">
|
| 263 |
+
<figcaption>Visual at {{ seg.start_seconds | timestamp }}</figcaption>
|
| 264 |
+
</figure>
|
| 265 |
+
|
| 266 |
+
<h3>Narration</h3>
|
| 267 |
+
<p contenteditable="true" data-bind="narration" spellcheck="true">{{ seg.narration }}</p>
|
| 268 |
+
|
| 269 |
+
<details class="ocr">
|
| 270 |
+
<summary>On-screen text (OCR)</summary>
|
| 271 |
+
<div contenteditable="true" data-bind="ocr_text" spellcheck="true">{{ seg.ocr_text }}</div>
|
| 272 |
+
</details>
|
| 273 |
+
</article>
|
| 274 |
+
{% endfor %}
|
| 275 |
+
</main>
|
| 276 |
+
|
| 277 |
+
<footer class="page-footer" role="contentinfo">
|
| 278 |
+
<p class="meta">Generated by VideoGuideMaker. Verify accessibility before distribution.</p>
|
| 279 |
+
</footer>
|
| 280 |
+
|
| 281 |
+
<script>
|
| 282 |
+
(function () {
|
| 283 |
+
const root = document;
|
| 284 |
+
const toolbar = root.querySelector('.vgm-toolbar');
|
| 285 |
+
const status = toolbar.querySelector('.vgm-status');
|
| 286 |
+
const titleEl = root.querySelector('[data-bind="title"]');
|
| 287 |
+
|
| 288 |
+
function setStatus(msg) {
|
| 289 |
+
status.textContent = msg;
|
| 290 |
+
if (msg) setTimeout(() => { if (status.textContent === msg) status.textContent = ''; }, 4000);
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
function getSegmentEls() {
|
| 294 |
+
return Array.from(root.querySelectorAll('article.segment'));
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
function syncSegmentBindings(article) {
|
| 298 |
+
const titleInput = article.querySelector('input[data-bind="section_title"]');
|
| 299 |
+
const altInput = article.querySelector('input[data-bind="alt_text"]');
|
| 300 |
+
const includeBox = article.querySelector('input[data-bind="include"]');
|
| 301 |
+
const heading = article.querySelector('[data-bind-target="section_title"]');
|
| 302 |
+
const img = article.querySelector('[data-bind-target="alt_text"]');
|
| 303 |
+
|
| 304 |
+
titleInput.addEventListener('input', () => { heading.textContent = titleInput.value; });
|
| 305 |
+
altInput.addEventListener('input', () => { img.setAttribute('alt', altInput.value); });
|
| 306 |
+
includeBox.addEventListener('change', () => {
|
| 307 |
+
article.setAttribute('data-included', includeBox.checked ? 'true' : 'false');
|
| 308 |
+
});
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
function syncTitle() {
|
| 312 |
+
const update = () => {
|
| 313 |
+
const t = titleEl.textContent.trim() || 'Study Guide';
|
| 314 |
+
document.title = t;
|
| 315 |
+
};
|
| 316 |
+
titleEl.addEventListener('input', update);
|
| 317 |
+
update();
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
function readState() {
|
| 321 |
+
return {
|
| 322 |
+
title: titleEl.textContent.trim(),
|
| 323 |
+
segments: getSegmentEls().map(a => ({
|
| 324 |
+
index: parseInt(a.getAttribute('data-segment-index'), 10),
|
| 325 |
+
section_title: a.querySelector('input[data-bind="section_title"]').value,
|
| 326 |
+
alt_text: a.querySelector('input[data-bind="alt_text"]').value,
|
| 327 |
+
narration: a.querySelector('[data-bind="narration"]').textContent,
|
| 328 |
+
ocr_text: a.querySelector('[data-bind="ocr_text"]').textContent,
|
| 329 |
+
include: a.querySelector('input[data-bind="include"]').checked,
|
| 330 |
+
})),
|
| 331 |
+
};
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
function applyState(state) {
|
| 335 |
+
if (typeof state.title === 'string') {
|
| 336 |
+
titleEl.textContent = state.title;
|
| 337 |
+
document.title = state.title;
|
| 338 |
+
}
|
| 339 |
+
const byIndex = new Map();
|
| 340 |
+
getSegmentEls().forEach(a => byIndex.set(parseInt(a.getAttribute('data-segment-index'), 10), a));
|
| 341 |
+
(state.segments || []).forEach(s => {
|
| 342 |
+
const a = byIndex.get(s.index);
|
| 343 |
+
if (!a) return;
|
| 344 |
+
if ('section_title' in s) {
|
| 345 |
+
const el = a.querySelector('input[data-bind="section_title"]');
|
| 346 |
+
el.value = s.section_title;
|
| 347 |
+
a.querySelector('[data-bind-target="section_title"]').textContent = s.section_title;
|
| 348 |
+
}
|
| 349 |
+
if ('alt_text' in s) {
|
| 350 |
+
const el = a.querySelector('input[data-bind="alt_text"]');
|
| 351 |
+
el.value = s.alt_text;
|
| 352 |
+
a.querySelector('[data-bind-target="alt_text"]').setAttribute('alt', s.alt_text);
|
| 353 |
+
}
|
| 354 |
+
if ('narration' in s) a.querySelector('[data-bind="narration"]').textContent = s.narration;
|
| 355 |
+
if ('ocr_text' in s) a.querySelector('[data-bind="ocr_text"]').textContent = s.ocr_text;
|
| 356 |
+
if ('include' in s) {
|
| 357 |
+
a.querySelector('input[data-bind="include"]').checked = !!s.include;
|
| 358 |
+
a.setAttribute('data-included', s.include ? 'true' : 'false');
|
| 359 |
+
}
|
| 360 |
+
});
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function saveJSON() {
|
| 364 |
+
const blob = new Blob([JSON.stringify(readState(), null, 2)], { type: 'application/json' });
|
| 365 |
+
const url = URL.createObjectURL(blob);
|
| 366 |
+
const a = document.createElement('a');
|
| 367 |
+
a.href = url;
|
| 368 |
+
a.download = (titleEl.textContent.trim() || 'study-guide').replace(/[^A-Za-z0-9._-]+/g, '-') + '.edits.json';
|
| 369 |
+
document.body.appendChild(a); a.click(); a.remove();
|
| 370 |
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
| 371 |
+
setStatus('Saved edits to JSON.');
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
function loadJSON(file) {
|
| 375 |
+
const reader = new FileReader();
|
| 376 |
+
reader.onload = () => {
|
| 377 |
+
try {
|
| 378 |
+
const state = JSON.parse(reader.result);
|
| 379 |
+
applyState(state);
|
| 380 |
+
setStatus('Loaded edits from JSON.');
|
| 381 |
+
} catch (e) {
|
| 382 |
+
setStatus('Could not parse JSON: ' + e.message);
|
| 383 |
+
}
|
| 384 |
+
};
|
| 385 |
+
reader.readAsText(file);
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
function buildFinalHTML() {
|
| 389 |
+
const clone = root.documentElement.cloneNode(true);
|
| 390 |
+
clone.removeAttribute('data-vgm-review');
|
| 391 |
+
|
| 392 |
+
clone.querySelectorAll('[data-editor]').forEach(el => el.remove());
|
| 393 |
+
clone.querySelectorAll('script').forEach(el => el.remove());
|
| 394 |
+
|
| 395 |
+
// Apply current alt-text values to images, then drop the input rows (already removed above).
|
| 396 |
+
// Drop segments that are excluded.
|
| 397 |
+
const removedIds = new Set();
|
| 398 |
+
clone.querySelectorAll('article.segment[data-included="false"]').forEach(a => {
|
| 399 |
+
removedIds.add(a.id);
|
| 400 |
+
a.remove();
|
| 401 |
+
});
|
| 402 |
+
|
| 403 |
+
// Strip contenteditable affordances.
|
| 404 |
+
clone.querySelectorAll('[contenteditable]').forEach(el => {
|
| 405 |
+
el.removeAttribute('contenteditable');
|
| 406 |
+
el.removeAttribute('spellcheck');
|
| 407 |
+
});
|
| 408 |
+
|
| 409 |
+
// Mark alt as reviewed (no longer a draft) on remaining images.
|
| 410 |
+
clone.querySelectorAll('article.segment img').forEach(img => {
|
| 411 |
+
img.removeAttribute('data-bind-target');
|
| 412 |
+
});
|
| 413 |
+
|
| 414 |
+
// Remove data-bind helpers everywhere.
|
| 415 |
+
clone.querySelectorAll('[data-bind], [data-bind-target]').forEach(el => {
|
| 416 |
+
el.removeAttribute('data-bind');
|
| 417 |
+
el.removeAttribute('data-bind-target');
|
| 418 |
+
});
|
| 419 |
+
|
| 420 |
+
// Rebuild TOC from the remaining segments, renumbering captions.
|
| 421 |
+
const toc = clone.querySelector('nav.toc');
|
| 422 |
+
const remaining = Array.from(clone.querySelectorAll('article.segment'));
|
| 423 |
+
if (toc) {
|
| 424 |
+
if (remaining.length < 2) {
|
| 425 |
+
toc.remove();
|
| 426 |
+
} else {
|
| 427 |
+
const ol = toc.querySelector('ol');
|
| 428 |
+
ol.innerHTML = '';
|
| 429 |
+
remaining.forEach(a => {
|
| 430 |
+
const heading = a.querySelector('[id$="-heading"]');
|
| 431 |
+
const sectionTitle = heading ? heading.textContent.trim() : a.id;
|
| 432 |
+
const li = clone.ownerDocument.createElement('li');
|
| 433 |
+
const link = clone.ownerDocument.createElement('a');
|
| 434 |
+
link.setAttribute('href', '#' + a.id);
|
| 435 |
+
link.textContent = sectionTitle;
|
| 436 |
+
li.appendChild(link);
|
| 437 |
+
ol.appendChild(li);
|
| 438 |
+
});
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
// Drop the now-redundant review-mode notice and leave a clean accessibility note.
|
| 443 |
+
// (Already removed via [data-editor].)
|
| 444 |
+
|
| 445 |
+
// Reset top padding that made room for the toolbar.
|
| 446 |
+
const header = clone.querySelector('header.page-header');
|
| 447 |
+
if (header) header.style.paddingTop = '';
|
| 448 |
+
|
| 449 |
+
return '<!doctype html>\n' + clone.outerHTML;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
function downloadHTML() {
|
| 453 |
+
const html = buildFinalHTML();
|
| 454 |
+
const blob = new Blob([html], { type: 'text/html;charset=utf-8' });
|
| 455 |
+
const url = URL.createObjectURL(blob);
|
| 456 |
+
const a = document.createElement('a');
|
| 457 |
+
a.href = url;
|
| 458 |
+
a.download = (titleEl.textContent.trim() || 'study-guide').replace(/[^A-Za-z0-9._-]+/g, '-') + '.html';
|
| 459 |
+
document.body.appendChild(a); a.click(); a.remove();
|
| 460 |
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
| 461 |
+
setStatus('Downloaded final HTML.');
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
toolbar.querySelector('[data-action="save-json"]').addEventListener('click', saveJSON);
|
| 465 |
+
toolbar.querySelector('[data-action="download-html"]').addEventListener('click', downloadHTML);
|
| 466 |
+
toolbar.querySelector('[data-action="load-json"]').addEventListener('change', e => {
|
| 467 |
+
const f = e.target.files && e.target.files[0];
|
| 468 |
+
if (f) loadJSON(f);
|
| 469 |
+
e.target.value = '';
|
| 470 |
+
});
|
| 471 |
+
|
| 472 |
+
getSegmentEls().forEach(syncSegmentBindings);
|
| 473 |
+
syncTitle();
|
| 474 |
+
})();
|
| 475 |
+
</script>
|
| 476 |
+
</body>
|
| 477 |
+
</html>
|
|
@@ -4,6 +4,8 @@ from pathlib import Path
|
|
| 4 |
|
| 5 |
from PIL import Image
|
| 6 |
|
|
|
|
|
|
|
| 7 |
from app.pipeline.html_gen import (
|
| 8 |
Segment,
|
| 9 |
_draft_alt_from_ocr,
|
|
@@ -11,6 +13,7 @@ from app.pipeline.html_gen import (
|
|
| 11 |
bundle_zip,
|
| 12 |
build_segments,
|
| 13 |
render_guide,
|
|
|
|
| 14 |
)
|
| 15 |
from app.pipeline.types import SceneFrame
|
| 16 |
|
|
@@ -58,6 +61,52 @@ def test_render_guide_inline_images_embeds_data_uri(tmp_path):
|
|
| 58 |
assert "data:image/jpeg;base64," in html
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def test_bundle_zip_packages_html_and_images(tmp_path):
|
| 62 |
img = tmp_path / "scene_0000.jpg"
|
| 63 |
_make_image(img)
|
|
|
|
| 4 |
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
from app.pipeline.html_gen import (
|
| 10 |
Segment,
|
| 11 |
_draft_alt_from_ocr,
|
|
|
|
| 13 |
bundle_zip,
|
| 14 |
build_segments,
|
| 15 |
render_guide,
|
| 16 |
+
render_review,
|
| 17 |
)
|
| 18 |
from app.pipeline.types import SceneFrame
|
| 19 |
|
|
|
|
| 61 |
assert "data:image/jpeg;base64," in html
|
| 62 |
|
| 63 |
|
| 64 |
+
def test_build_segments_assigns_default_section_titles(tmp_path):
|
| 65 |
+
img1 = tmp_path / "scene_0000.jpg"
|
| 66 |
+
img2 = tmp_path / "scene_0001.jpg"
|
| 67 |
+
_make_image(img1)
|
| 68 |
+
_make_image(img2)
|
| 69 |
+
frames = [SceneFrame(0, 0.0, 5.0, img1), SceneFrame(1, 5.0, 65.0, img2)]
|
| 70 |
+
segments = build_segments(frames, ["", ""], ["", ""], inline_images=False)
|
| 71 |
+
assert segments[0].section_title == "Segment 1 — 0:00"
|
| 72 |
+
assert segments[1].section_title == "Segment 2 — 0:05"
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def test_render_review_emits_editor_chrome_and_bindings(tmp_path):
|
| 76 |
+
img = tmp_path / "scene_0000.jpg"
|
| 77 |
+
_make_image(img)
|
| 78 |
+
frame = SceneFrame(0, 0.0, 5.0, img)
|
| 79 |
+
segments = build_segments(frame and [frame], ["The narration."], ["OCR content"], inline_images=True)
|
| 80 |
+
html = render_review("Review Me", segments, lang="en")
|
| 81 |
+
|
| 82 |
+
assert 'data-vgm-review="1"' in html
|
| 83 |
+
assert 'class="vgm-toolbar"' in html
|
| 84 |
+
assert 'data-action="save-json"' in html
|
| 85 |
+
assert 'data-action="load-json"' in html
|
| 86 |
+
assert 'data-action="download-html"' in html
|
| 87 |
+
assert 'data-bind="title"' in html
|
| 88 |
+
assert 'data-bind="section_title"' in html
|
| 89 |
+
assert 'data-bind="alt_text"' in html
|
| 90 |
+
assert 'data-bind="include"' in html
|
| 91 |
+
assert 'data-bind="narration"' in html
|
| 92 |
+
assert 'data-bind="ocr_text"' in html
|
| 93 |
+
assert 'data-bind-target="section_title"' in html
|
| 94 |
+
assert 'data-bind-target="alt_text"' in html
|
| 95 |
+
assert "The narration." in html
|
| 96 |
+
assert "OCR content" in html
|
| 97 |
+
assert 'data-included="true"' in html
|
| 98 |
+
assert "data:image/jpeg;base64," in html
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def test_render_review_requires_inline_images(tmp_path):
|
| 102 |
+
img = tmp_path / "scene_0000.jpg"
|
| 103 |
+
_make_image(img)
|
| 104 |
+
frame = SceneFrame(0, 0.0, 5.0, img)
|
| 105 |
+
segments = build_segments([frame], [""], [""], inline_images=False)
|
| 106 |
+
with pytest.raises(ValueError):
|
| 107 |
+
render_review("Bad", segments)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
def test_bundle_zip_packages_html_and_images(tmp_path):
|
| 111 |
img = tmp_path / "scene_0000.jpg"
|
| 112 |
_make_image(img)
|