joemartis commited on
Commit
09f7889
Β·
2 Parent(s): b8bef4c5d54c1c

Merge pull request #64 from JoeMartis/claude/fix-zip-path-traversal-9kA4Q

Browse files
app/pipeline/orchestrator.py CHANGED
@@ -178,13 +178,16 @@ def _apply_topic_segmentation(
178
  continue
179
  scenes.sort(key=lambda s: s.start_seconds)
180
  # Pool the scenes by "is this clearly a slide?":
181
- # slide_text β€” substantial OCR text on the frame (the strongest
182
- # signal we have that it's actual slide content, not a
183
- # talking-head shot the face filter let through).
 
 
184
  # clean_visual β€” no slide text but very small face area, so
185
  # probably a decorative/photo slide (still useful).
186
  # borderline β€” everything else (talking heads that squeaked
187
- # past the instructor filter).
 
188
  # Always pick from the highest non-empty pool, then take the
189
  # longest-on-screen scene within it.
190
  slide_text: list[SceneFrame] = []
@@ -192,7 +195,7 @@ def _apply_topic_segmentation(
192
  borderline: list[SceneFrame] = []
193
  for s in scenes:
194
  text = ocr_by_id.get(id(s), "")
195
- if len(text.strip()) >= _SLIDE_CONTENT_OCR_CHARS:
196
  slide_text.append(s)
197
  elif s.face_area_ratio < _SLIDE_CONTENT_FACE_RATIO:
198
  clean_visual.append(s)
@@ -227,12 +230,6 @@ def _apply_topic_segmentation(
227
  # instructor close-ups that snuck past.
228
  _SLIDE_CONTENT_FACE_RATIO = 0.03
229
 
230
- # Minimum OCR character count for a scene to be treated as "clearly
231
- # slide content" when picking a topic's primary frame. Empirically
232
- # anything with β‰₯30 chars of recognised text is at least a title slide
233
- # or a short bullet β€” pure talking-head frames OCR to ≀ a few stray chars.
234
- _SLIDE_CONTENT_OCR_CHARS = 30
235
-
236
 
237
  def _load_cues(inputs: PipelineInputs) -> tuple[list[Cue], bool]:
238
  """Return (cues, used_auto_transcribe)."""
 
178
  continue
179
  scenes.sort(key=lambda s: s.start_seconds)
180
  # Pool the scenes by "is this clearly a slide?":
181
+ # slide_text β€” any non-empty OCR output. `ocr_frame` already
182
+ # filters by per-word confidence and a 3-char alnum run, so
183
+ # a non-empty return value is by definition real text. Any
184
+ # real text β€” a title card like "HEAT PUMPS", a bullet
185
+ # slide, a labelled photo β€” should beat a talking head.
186
  # clean_visual β€” no slide text but very small face area, so
187
  # probably a decorative/photo slide (still useful).
188
  # borderline β€” everything else (talking heads that squeaked
189
+ # past the instructor filter, or faceless frames where
190
+ # OCR found nothing).
191
  # Always pick from the highest non-empty pool, then take the
192
  # longest-on-screen scene within it.
193
  slide_text: list[SceneFrame] = []
 
195
  borderline: list[SceneFrame] = []
196
  for s in scenes:
197
  text = ocr_by_id.get(id(s), "")
198
+ if text.strip():
199
  slide_text.append(s)
200
  elif s.face_area_ratio < _SLIDE_CONTENT_FACE_RATIO:
201
  clean_visual.append(s)
 
230
  # instructor close-ups that snuck past.
231
  _SLIDE_CONTENT_FACE_RATIO = 0.03
232
 
 
 
 
 
 
 
233
 
234
  def _load_cues(inputs: PipelineInputs) -> tuple[list[Cue], bool]:
235
  """Return (cues, used_auto_transcribe)."""
tests/test_topic_segmentation.py CHANGED
@@ -364,9 +364,9 @@ def test_apply_topic_segmentation_returns_ocr_aligned_to_new_primaries():
364
  scenes,
365
  topics,
366
  scene_ocr_texts=[
367
- "Slide zero text " * 5, # β‰₯30 chars: a real slide
368
- "Slide one text " * 5,
369
- "Slide two content " * 5,
370
  ],
371
  )
372
  assert len(new_kept) == 2
@@ -374,6 +374,30 @@ def test_apply_topic_segmentation_returns_ocr_aligned_to_new_primaries():
374
  assert "Slide two" in primary_ocr[1]
375
 
376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  def test_apply_topic_segmentation_handles_empty_input():
378
  """Defensive: no scenes or no topics β†’ return inputs unchanged."""
379
  assert _apply_topic_segmentation([], []) == ([], [], [], [])
 
364
  scenes,
365
  topics,
366
  scene_ocr_texts=[
367
+ "Slide zero text", # any non-empty OCR output = real slide content
368
+ "Slide one text",
369
+ "Slide two content",
370
  ],
371
  )
372
  assert len(new_kept) == 2
 
374
  assert "Slide two" in primary_ocr[1]
375
 
376
 
377
+ def test_apply_topic_segmentation_short_title_card_beats_longer_talking_head():
378
+ """User-reported regression from the heat-pump lecture: a short
379
+ "HEAT PUMPS" title card OCRs to roughly 10 characters and the old
380
+ 30-char floor dropped it out of the slide_text pool, so a longer
381
+ talking-head shot won by duration. With the relaxed "any non-empty
382
+ OCR" check, the title card wins as it should.
383
+ """
384
+ scenes = [
385
+ # Long borderline talking-head, no OCR text.
386
+ _sf(0, 0.0, 40.0, face_area_ratio=0.08),
387
+ # Short title-card slide with just "HEAT PUMPS".
388
+ _sf(1, 40.0, 50.0, face_area_ratio=0.0),
389
+ ]
390
+ topics = [Topic(start_seconds=0.0, end_seconds=60.0, title="Heat pumps")]
391
+ new_kept, _, _, primary_ocr = _apply_topic_segmentation(
392
+ scenes,
393
+ topics,
394
+ scene_ocr_texts=["", "HEAT PUMPS"],
395
+ )
396
+ assert len(new_kept) == 1
397
+ assert new_kept[0].image_path.name == "scene_0001.jpg"
398
+ assert primary_ocr[0] == "HEAT PUMPS"
399
+
400
+
401
  def test_apply_topic_segmentation_handles_empty_input():
402
  """Defensive: no scenes or no topics β†’ return inputs unchanged."""
403
  assert _apply_topic_segmentation([], []) == ([], [], [], [])