Spaces:
Build error
Build error
anwarKXC commited on
Commit ยท
b36c6c1
1
Parent(s): 8ea168e
fix: forward layout headings to candidate pool in detect_headings_async
Browse filesFiles changed (2)
564 unmodified lines565566567568569570571572573574575576577564 unmodified linesocr_pages: page numbers that needed OCR fallback during extraction โused to discount candidates found on those pages slightlymore (OCR is noisier than native PDF text).Returns:(headings, metrics) โ metrics is a JSON-able summary worth loggingor storing per document (see module docstring for shape)."""candidates, total_pages, ocr_stats = await asyncio.to_thread(_build_candidate_pool, pdf_bytes, pages, ocr_pages,)candidates = _sanitize_candidates(candidates)candidates = _merge_candidates(candidates)564 unmodified lines565566567568569570571572573574575576577578579580564 unmodified linesocr_pages: page numbers that needed OCR fallback during extraction โused to discount candidates found on those pages slightlymore (OCR is noisier than native PDF text).layout_headings: page_num -> heading texts recovered from the OCRbounding-box geometry (see ocr_layout.py). The only sourcethat can see a heading carrying no keyword and no number.Returns:(headings, metrics) โ metrics is a JSON-able summary worth loggingor storing per document (see module docstring for shape)."""candidates, total_pages, ocr_stats = await asyncio.to_thread(_build_candidate_pool, pdf_bytes, pages, ocr_pages, layout_headings,)candidates = _sanitize_candidates(candidates)candidates = _merge_candidates(candidates)
681 unmodified lines682683684681 unmodified linesassert "ุงูุงูุฏุงู" not in titleassert "ุชุฐูุฑ" not in titleassert title == "ุงููุญุฏู ุงูุงููู ุงููุทู ูุงูุงู ูุงุก"681 unmodified lines682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723681 unmodified linesassert "ุงูุงูุฏุงู" not in titleassert "ุชุฐูุฑ" not in titleassert title == "ุงููุญุฏู ุงูุงููู ุงููุทู ูุงูุงู ูุงุก"# โโ Layout headings must actually reach the pool (2026-08-07) โโโโโโโโโโdef test_layout_headings_are_forwarded_to_the_candidate_pool():"""The bug every other layout test was blind to.`detect_headings_async` accepted `layout_headings` and then called`_build_candidate_pool` without it, so the parameter defaulted to None andthe geometry source never ran on any book โ `accepted_by.ocr_layout` was 0even on a document where the extractor had found 118 headings across 74pages. The existing tests all called `_candidates_from_ocr_layout`directly, so the leaf worked and the wiring was never exercised."""import asyncioimport fitzfrom app.services.heading_detector import detect_headings_asyncdoc = fitz.open()for _ in range(6):doc.new_page()pdf_bytes = doc.tobytes()doc.close()body = ("ููุฌุง ุงููุจุงุช ุงูู ูุณุงุฆู ูุซูุฑู ูุฏุนู ู ู ููุง ุชุฑุณูุจ ุจุนุถ ุงูู ูุงุฏ ูู ุฌุฏุฑ ""ุฎูุงูุงู ูููู ุชุญุงูุธ ุงูุงูุณุฌู ุงูุฎุงุฑุฌูู ุนูู ุงูุณุฌู ุงููุจุงุช ุงูุฏุงุฎููู")pages = [(n, body) for n in range(1, 7)]_, metrics = asyncio.run(detect_headings_async(pdf_bytes,pages,ocr_pages=set(range(1, 7)),layout_headings={4: ["ุงูุฏุนุงู ู ูู ุงููุจุงุช"]},))sources = [s for e in metrics["debug_report"] for s in e["sources"]]assert "ocr_layout" in sources, metrics["debug_report"]
app/services/heading_detector.py+4-1
tests/test_heading_detector.py+39