Spaces:
Running
Running
Download tests/test_llm_replace_ocr.py from joemartis/Video2Guide: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/spaces/joemartis/Video2Guide/resolve/main/tests/test_llm_replace_ocr.py
- Command line
-
hf download hf://spaces/joemartis/Video2Guide/tests/test_llm_replace_ocr.py
-
curl -L -o test_llm_replace_ocr.py https://huggingface.co/spaces/joemartis/Video2Guide/resolve/main/tests/test_llm_replace_ocr.py
2.5 kB
| """Tests for the Tesseract-skip-when-LLM-replaces-OCR decision. | |
| The orchestrator skips the Tesseract pass when Claude is going to | |
| overwrite every frame's on-screen text anyway, except in topic mode | |
| where Tesseract output is still needed to pick each topic's primary | |
| frame from its scene pool. | |
| """ | |
| from pathlib import Path | |
| from app.pipeline.llm_extract import LLMToggles | |
| from app.pipeline.orchestrator import PipelineInputs, _llm_will_replace_tesseract | |
| def _inputs(**overrides) -> PipelineInputs: | |
| defaults = dict( | |
| video_path=Path("video.mp4"), | |
| transcript_path=None, | |
| frames_dir=Path("frames"), | |
| title="t", | |
| ) | |
| defaults.update(overrides) | |
| return PipelineInputs(**defaults) | |
| def test_skips_tesseract_when_llm_ocr_on_no_topic_seg(): | |
| inputs = _inputs( | |
| anthropic_api_key="sk-stub", | |
| llm_toggles=LLMToggles(ocr_text=True), | |
| ) | |
| assert _llm_will_replace_tesseract(inputs) is True | |
| def test_keeps_tesseract_in_topic_segmentation_mode(): | |
| """Topic-primary picking pools scenes by OCR character count to | |
| push talking-head shots out of the way; skipping Tesseract here | |
| would lose that signal and regress the recent fix. | |
| """ | |
| inputs = _inputs( | |
| anthropic_api_key="sk-stub", | |
| llm_toggles=LLMToggles(ocr_text=True, topic_segmentation=True), | |
| ) | |
| assert _llm_will_replace_tesseract(inputs) is False | |
| def test_keeps_tesseract_when_llm_ocr_toggle_is_off(): | |
| """When the LLM isn't going to provide on-screen text, Tesseract | |
| is the only OCR source — never skip. | |
| """ | |
| inputs = _inputs( | |
| anthropic_api_key="sk-stub", | |
| llm_toggles=LLMToggles(ocr_text=False, alt_text=True, math_equations=True), | |
| ) | |
| assert _llm_will_replace_tesseract(inputs) is False | |
| def test_keeps_tesseract_when_no_api_key(): | |
| """`llm_ocr_text` is on but no key was provided; the LLM call | |
| would no-op, so Tesseract must still run. | |
| """ | |
| inputs = _inputs( | |
| anthropic_api_key=None, | |
| llm_toggles=LLMToggles(ocr_text=True), | |
| ) | |
| assert _llm_will_replace_tesseract(inputs) is False | |
| def test_skip_ocr_flag_short_circuits_the_check(): | |
| """If the user explicitly opted out of OCR, we don't run Tesseract | |
| OR ask the LLM for text — the flag wins regardless of toggles. | |
| """ | |
| inputs = _inputs( | |
| skip_ocr=True, | |
| anthropic_api_key="sk-stub", | |
| llm_toggles=LLMToggles(ocr_text=True), | |
| ) | |
| assert _llm_will_replace_tesseract(inputs) is False | |