Spaces:
Running
Running
Download rag/liteparse_utils.py from Deign86/mathpulse-api-v3test: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/Deign86/mathpulse-api-v3test/resolve/main/rag/liteparse_utils.py
- Command line
-
hf download hf://spaces/Deign86/mathpulse-api-v3test/rag/liteparse_utils.py
-
curl -L -o liteparse_utils.py https://huggingface.co/spaces/Deign86/mathpulse-api-v3test/resolve/main/rag/liteparse_utils.py
1.03 kB
| """Small LiteParse adapter shared by curriculum and upload ingestion paths.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Any | |
| def parse_document(content: bytes | str | Path) -> Any: | |
| """Parse a document with LiteParse, accepting paths or in-memory bytes.""" | |
| from liteparse import LiteParse | |
| return LiteParse(output_format="markdown").parse(content) | |
| def extract_text(content: bytes | str | Path) -> str: | |
| """Return LiteParse's rendered text for a document.""" | |
| text = getattr(parse_document(content), "text", "") | |
| return text if isinstance(text, str) else str(text or "") | |
| def extract_text_and_pages(content: bytes | str | Path) -> tuple[str, list[int]]: | |
| """Return text and conservative page offsets for legacy chunking callers. | |
| LiteParse's stable Python contract exposes rendered document text. Page-level | |
| objects vary by parser output, so callers retain a single-document offset. | |
| """ | |
| text = extract_text(content) | |
| return text, [0] if text else [] | |