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 lines565566567568569570571572573574575576574577578579580564 unmodified lines ocr_pages: page numbers that needed OCR fallback during extraction โ used to discount candidates found on those pages slightly more (OCR is noisier than native PDF text). layout_headings: page_num -> heading texts recovered from the OCR bounding-box geometry (see ocr_layout.py). The only source that can see a heading carrying no keyword and no number.
Returns: (headings, metrics) โ metrics is a JSON-able summary worth logging or 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, _build_candidate_pool, pdf_bytes, pages, ocr_pages, layout_headings, ) candidates = _sanitize_candidates(candidates) candidates = _merge_candidates(candidates)681 unmodified lines682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723681 unmodified lines assert "ุงูุงูุฏุงู" not in title assert "ุชุฐูุฑ" not in title assert 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 and the geometry source never ran on any book โ `accepted_by.ocr_layout` was 0 even on a document where the extractor had found 118 headings across 74 pages. The existing tests all called `_candidates_from_ocr_layout` directly, so the leaf worked and the wiring was never exercised. """ import asyncio
import fitz
from app.services.heading_detector import detect_headings_async
doc = 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