Spaces:
Sleeping
feat: make the transcript optional in images mode
Browse filesOn /images you can now omit the transcript and get a slides-only guide:
each image anchored at its timestamp, no narration. Useful when you just
want an accessible image deck (especially with AI scene descriptions /
alt-text turned on).
Wiring:
* build_frames_from_images: transcript_end is now optional. With none,
timestamp parsing skips the range guard and the last slide runs to its
own timestamp (no known end).
* PipelineInputs gains allow_empty_transcript (default False, so the
video path still fails fast on a missing transcript). When True,
_load_cues returns [] for a missing transcript and run_pipeline skips
the zero-cues error β a slides-only guide is a valid result there.
* /jobs/from-images: transcript is optional (File(None)); "no filename"
is treated as no transcript. transcript_path/transcript_end stay None,
allow_empty_transcript=True. Topic segmentation still requires a
transcript, so it's rejected with a clear 400 when absent.
* images.html: transcript field no longer required; hint explains the
slides-only option.
Test: build_frames_from_images with no transcript_end (ordering +
last-slide-to-own-timestamp).
https://claude.ai/code/session_01EM8jiYxdVFy1w3LeJ9GBJg
- app/main.py +30 -13
- app/pipeline/image_input.py +16 -10
- app/pipeline/orchestrator.py +11 -2
- app/templates/images.html +3 -3
- tests/test_image_input.py +14 -0
|
@@ -1009,7 +1009,7 @@ async def start_job(
|
|
| 1009 |
async def start_job_from_images(
|
| 1010 |
title: str = Form(...),
|
| 1011 |
images: list[UploadFile] = File(...),
|
| 1012 |
-
transcript: UploadFile = File(
|
| 1013 |
format: str = Form("review"),
|
| 1014 |
subtitle: str | None = Form(None),
|
| 1015 |
module: str | None = Form(None),
|
|
@@ -1036,8 +1036,13 @@ async def start_job_from_images(
|
|
| 1036 |
"""
|
| 1037 |
if format not in ALLOWED_FORMATS:
|
| 1038 |
raise HTTPException(400, f"Unknown output format: {format}")
|
| 1039 |
-
|
| 1040 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1041 |
raise HTTPException(400, f"Unsupported transcript format: {transcript_suffix or '(none)'}")
|
| 1042 |
if not images:
|
| 1043 |
raise HTTPException(400, "At least one slide image is required.")
|
|
@@ -1058,6 +1063,13 @@ async def start_job_from_images(
|
|
| 1058 |
"AI features were requested but no Anthropic API key was provided. "
|
| 1059 |
"Add a key or uncheck the AI features.",
|
| 1060 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1061 |
if llm_topic_segmentation and not is_valid_video_type(llm_topic_video_type):
|
| 1062 |
raise HTTPException(
|
| 1063 |
400,
|
|
@@ -1068,17 +1080,21 @@ async def start_job_from_images(
|
|
| 1068 |
workdir = Path(tempfile.mkdtemp(prefix="vgm_img_"))
|
| 1069 |
handed_off = False
|
| 1070 |
try:
|
| 1071 |
-
transcript_path
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
raise HTTPException(
|
| 1078 |
-
400,
|
| 1079 |
-
"Transcript parsed to zero cues. Provide a non-empty VTT/SRT file.",
|
| 1080 |
)
|
| 1081 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1082 |
|
| 1083 |
frames_dir = workdir / "static"
|
| 1084 |
frames_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -1131,6 +1147,7 @@ async def start_job_from_images(
|
|
| 1131 |
topic_video_type=llm_topic_video_type,
|
| 1132 |
),
|
| 1133 |
extract_audio=False, # no source video to slice
|
|
|
|
| 1134 |
)
|
| 1135 |
|
| 1136 |
try:
|
|
|
|
| 1009 |
async def start_job_from_images(
|
| 1010 |
title: str = Form(...),
|
| 1011 |
images: list[UploadFile] = File(...),
|
| 1012 |
+
transcript: UploadFile | None = File(None),
|
| 1013 |
format: str = Form("review"),
|
| 1014 |
subtitle: str | None = Form(None),
|
| 1015 |
module: str | None = Form(None),
|
|
|
|
| 1036 |
"""
|
| 1037 |
if format not in ALLOWED_FORMATS:
|
| 1038 |
raise HTTPException(400, f"Unknown output format: {format}")
|
| 1039 |
+
# The transcript is OPTIONAL in images mode: with none, the guide is
|
| 1040 |
+
# built from the slides alone (no narration). FastAPI can hand us an
|
| 1041 |
+
# empty UploadFile with a blank filename for an omitted field, so treat
|
| 1042 |
+
# "no filename" as "no transcript".
|
| 1043 |
+
has_transcript = bool(transcript is not None and (transcript.filename or "").strip())
|
| 1044 |
+
transcript_suffix = Path(transcript.filename or "").suffix.lower() if has_transcript else ""
|
| 1045 |
+
if has_transcript and transcript_suffix not in TRANSCRIPT_SUFFIXES:
|
| 1046 |
raise HTTPException(400, f"Unsupported transcript format: {transcript_suffix or '(none)'}")
|
| 1047 |
if not images:
|
| 1048 |
raise HTTPException(400, "At least one slide image is required.")
|
|
|
|
| 1063 |
"AI features were requested but no Anthropic API key was provided. "
|
| 1064 |
"Add a key or uncheck the AI features.",
|
| 1065 |
)
|
| 1066 |
+
# Topic segmentation reads the transcript; it can't run without one.
|
| 1067 |
+
if llm_topic_segmentation and not has_transcript:
|
| 1068 |
+
raise HTTPException(
|
| 1069 |
+
400,
|
| 1070 |
+
"Topic segmentation needs a transcript. Add one, or turn topic "
|
| 1071 |
+
"segmentation off.",
|
| 1072 |
+
)
|
| 1073 |
if llm_topic_segmentation and not is_valid_video_type(llm_topic_video_type):
|
| 1074 |
raise HTTPException(
|
| 1075 |
400,
|
|
|
|
| 1080 |
workdir = Path(tempfile.mkdtemp(prefix="vgm_img_"))
|
| 1081 |
handed_off = False
|
| 1082 |
try:
|
| 1083 |
+
transcript_path: Path | None = None
|
| 1084 |
+
transcript_end: float | None = None
|
| 1085 |
+
if has_transcript:
|
| 1086 |
+
transcript_path = workdir / f"transcript{transcript_suffix}"
|
| 1087 |
+
await _save_upload(
|
| 1088 |
+
transcript, transcript_path, max_bytes=MAX_TRANSCRIPT_BYTES, label="Transcript"
|
|
|
|
|
|
|
|
|
|
| 1089 |
)
|
| 1090 |
+
cues = parse_transcript(transcript_path)
|
| 1091 |
+
if not cues:
|
| 1092 |
+
raise HTTPException(
|
| 1093 |
+
400,
|
| 1094 |
+
"Transcript parsed to zero cues. Provide a non-empty VTT/SRT "
|
| 1095 |
+
"file, or omit the transcript entirely.",
|
| 1096 |
+
)
|
| 1097 |
+
transcript_end = cues[-1].end
|
| 1098 |
|
| 1099 |
frames_dir = workdir / "static"
|
| 1100 |
frames_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 1147 |
topic_video_type=llm_topic_video_type,
|
| 1148 |
),
|
| 1149 |
extract_audio=False, # no source video to slice
|
| 1150 |
+
allow_empty_transcript=True, # transcript optional in images mode
|
| 1151 |
)
|
| 1152 |
|
| 1153 |
try:
|
|
@@ -109,16 +109,18 @@ def parse_timestamp_from_name(
|
|
| 109 |
def build_frames_from_images(
|
| 110 |
images: list[Path],
|
| 111 |
*,
|
| 112 |
-
transcript_end: float,
|
| 113 |
) -> list[SceneFrame]:
|
| 114 |
"""Turn timestamp-named images into an ordered SceneFrame list.
|
| 115 |
|
| 116 |
-
``transcript_end`` is the last cue's end (seconds); it bounds
|
| 117 |
-
parsing and becomes the end of the final segment.
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
"""
|
| 123 |
if not images:
|
| 124 |
raise ImageInputError("No images were provided.")
|
|
@@ -140,12 +142,16 @@ def build_frames_from_images(
|
|
| 140 |
f"needs a distinct time."
|
| 141 |
)
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
frames: list[SceneFrame] = []
|
| 144 |
n = len(parsed)
|
| 145 |
for i, p in enumerate(parsed):
|
| 146 |
-
end = parsed[i + 1].timestamp if i + 1 < n else
|
| 147 |
-
# A slide placed at/after the
|
| 148 |
-
#
|
| 149 |
if end <= p.timestamp:
|
| 150 |
end = p.timestamp
|
| 151 |
frames.append(
|
|
|
|
| 109 |
def build_frames_from_images(
|
| 110 |
images: list[Path],
|
| 111 |
*,
|
| 112 |
+
transcript_end: float | None = None,
|
| 113 |
) -> list[SceneFrame]:
|
| 114 |
"""Turn timestamp-named images into an ordered SceneFrame list.
|
| 115 |
|
| 116 |
+
``transcript_end`` is the last cue's end (seconds); when given it bounds
|
| 117 |
+
timestamp parsing and becomes the end of the final segment. It is
|
| 118 |
+
optional β with no transcript there's no known timeline end, so parsing
|
| 119 |
+
runs without the range guard and the last slide simply runs to its own
|
| 120 |
+
timestamp. Each image anchors a segment that runs to the next image's
|
| 121 |
+
timestamp. Raises ImageInputError on an empty set, an unparseable name,
|
| 122 |
+
a duplicate timestamp, or (when a transcript bound is given) a timestamp
|
| 123 |
+
past the transcript.
|
| 124 |
"""
|
| 125 |
if not images:
|
| 126 |
raise ImageInputError("No images were provided.")
|
|
|
|
| 142 |
f"needs a distinct time."
|
| 143 |
)
|
| 144 |
|
| 145 |
+
# Without a transcript the final segment has no known end; run it to its
|
| 146 |
+
# own start (the meta-time then shows just that timestamp).
|
| 147 |
+
tail = transcript_end if transcript_end is not None else parsed[-1].timestamp
|
| 148 |
+
|
| 149 |
frames: list[SceneFrame] = []
|
| 150 |
n = len(parsed)
|
| 151 |
for i, p in enumerate(parsed):
|
| 152 |
+
end = parsed[i + 1].timestamp if i + 1 < n else tail
|
| 153 |
+
# A slide placed at/after the tail can't form a positive window;
|
| 154 |
+
# clamp its end so the segment is at least non-degenerate.
|
| 155 |
if end <= p.timestamp:
|
| 156 |
end = p.timestamp
|
| 157 |
frames.append(
|
|
@@ -75,6 +75,11 @@ class PipelineInputs:
|
|
| 75 |
# Slice narration audio per segment (one mono MP3 per kept segment).
|
| 76 |
# Off by default β opt in when learners actually need re-listenable clips.
|
| 77 |
extract_audio: bool = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
@dataclass
|
|
@@ -240,6 +245,9 @@ def _load_cues(inputs: PipelineInputs) -> tuple[list[Cue], bool]:
|
|
| 240 |
if inputs.transcript_path and inputs.transcript_path.exists():
|
| 241 |
log.info("Parsing transcript: %s", inputs.transcript_path)
|
| 242 |
return parse_transcript(inputs.transcript_path), False
|
|
|
|
|
|
|
|
|
|
| 243 |
if not inputs.auto_transcribe:
|
| 244 |
raise PipelineError(
|
| 245 |
"No transcript provided. Pass a VTT/SRT file or enable auto_transcribe."
|
|
@@ -303,11 +311,12 @@ def run_pipeline(
|
|
| 303 |
_emit(60, "transcript", "Loading transcript...")
|
| 304 |
cues, auto_transcribed = _load_cues(inputs)
|
| 305 |
log.info("Loaded %d cues (auto_transcribed=%s)", len(cues), auto_transcribed)
|
| 306 |
-
if not cues:
|
| 307 |
# Empty transcript silently produces a guide with no narration
|
| 308 |
# under any segment β surprising and unhelpful. Fail fast with
|
| 309 |
# a message that names the fix instead of letting the user
|
| 310 |
-
# discover empty paragraphs in the editor.
|
|
|
|
| 311 |
_emit(100, "error", "Transcript parsed to zero cues.")
|
| 312 |
raise PipelineError(
|
| 313 |
"Transcript parsed to zero cues. Provide a non-empty VTT/SRT "
|
|
|
|
| 75 |
# Slice narration audio per segment (one mono MP3 per kept segment).
|
| 76 |
# Off by default β opt in when learners actually need re-listenable clips.
|
| 77 |
extract_audio: bool = False
|
| 78 |
+
# When True, a missing/empty transcript is allowed: the guide is built
|
| 79 |
+
# from the slides alone (no narration). Used by the images-input mode
|
| 80 |
+
# where a transcript is optional. The video path leaves this False so a
|
| 81 |
+
# missing transcript still fails fast.
|
| 82 |
+
allow_empty_transcript: bool = False
|
| 83 |
|
| 84 |
|
| 85 |
@dataclass
|
|
|
|
| 245 |
if inputs.transcript_path and inputs.transcript_path.exists():
|
| 246 |
log.info("Parsing transcript: %s", inputs.transcript_path)
|
| 247 |
return parse_transcript(inputs.transcript_path), False
|
| 248 |
+
if inputs.allow_empty_transcript:
|
| 249 |
+
# Images mode with no transcript: no narration to align.
|
| 250 |
+
return [], False
|
| 251 |
if not inputs.auto_transcribe:
|
| 252 |
raise PipelineError(
|
| 253 |
"No transcript provided. Pass a VTT/SRT file or enable auto_transcribe."
|
|
|
|
| 311 |
_emit(60, "transcript", "Loading transcript...")
|
| 312 |
cues, auto_transcribed = _load_cues(inputs)
|
| 313 |
log.info("Loaded %d cues (auto_transcribed=%s)", len(cues), auto_transcribed)
|
| 314 |
+
if not cues and not inputs.allow_empty_transcript:
|
| 315 |
# Empty transcript silently produces a guide with no narration
|
| 316 |
# under any segment β surprising and unhelpful. Fail fast with
|
| 317 |
# a message that names the fix instead of letting the user
|
| 318 |
+
# discover empty paragraphs in the editor. (Images mode opts out:
|
| 319 |
+
# a slides-only guide with no narration is a valid choice there.)
|
| 320 |
_emit(100, "error", "Transcript parsed to zero cues.")
|
| 321 |
raise PipelineError(
|
| 322 |
"Transcript parsed to zero cues. Provide a non-empty VTT/SRT "
|
|
@@ -85,9 +85,9 @@
|
|
| 85 |
</div>
|
| 86 |
|
| 87 |
<div class="field">
|
| 88 |
-
<label for="transcript">Transcript</label>
|
| 89 |
-
<input type="file" id="transcript" name="transcript" accept=".vtt,.srt,text/vtt,application/x-subrip"
|
| 90 |
-
<p class="hint">A VTT or SRT covering the whole session
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<div class="field">
|
|
|
|
| 85 |
</div>
|
| 86 |
|
| 87 |
<div class="field">
|
| 88 |
+
<label for="transcript">Transcript <small>β optional</small></label>
|
| 89 |
+
<input type="file" id="transcript" name="transcript" accept=".vtt,.srt,text/vtt,application/x-subrip">
|
| 90 |
+
<p class="hint">A VTT or SRT covering the whole session adds the narration under each slide (its end also sets the last slide's span). Leave it out for a slides-only guide β just the images plus any AI descriptions/alt-text you enable.</p>
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<div class="field">
|
|
@@ -114,6 +114,20 @@ def test_build_frames_rejects_empty(tmp_path):
|
|
| 114 |
build_frames_from_images([], transcript_end=300.0)
|
| 115 |
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
def test_build_frames_last_slide_at_transcript_end(tmp_path):
|
| 118 |
# A slide right at the transcript end gets a non-degenerate (zero-width
|
| 119 |
# is clamped to itself) final window rather than crashing.
|
|
|
|
| 114 |
build_frames_from_images([], transcript_end=300.0)
|
| 115 |
|
| 116 |
|
| 117 |
+
def test_build_frames_without_transcript_end(tmp_path):
|
| 118 |
+
"""Transcript is optional: with no transcript_end, parsing runs without
|
| 119 |
+
the range guard and the last slide runs to its own timestamp."""
|
| 120 |
+
imgs = [
|
| 121 |
+
_touch(tmp_path, "00-00-00.png"),
|
| 122 |
+
_touch(tmp_path, "00-02-00.png"),
|
| 123 |
+
_touch(tmp_path, "00-05-30.png"),
|
| 124 |
+
]
|
| 125 |
+
frames = build_frames_from_images(imgs) # transcript_end omitted
|
| 126 |
+
assert [f.start_seconds for f in frames] == [0.0, 120.0, 330.0]
|
| 127 |
+
# Each end = next start; the LAST runs to its own start (no known end).
|
| 128 |
+
assert [f.end_seconds for f in frames] == [120.0, 330.0, 330.0]
|
| 129 |
+
|
| 130 |
+
|
| 131 |
def test_build_frames_last_slide_at_transcript_end(tmp_path):
|
| 132 |
# A slide right at the transcript end gets a non-degenerate (zero-width
|
| 133 |
# is clamped to itself) final window rather than crashing.
|