Spaces:
Running on Zero
Running on Zero
| from __future__ import annotations | |
| from pathlib import Path | |
| from ocr_studio.config import PAGE_BREAK | |
| PAGE_SEPARATOR = PAGE_BREAK | |
| def write_text_file(text: str, destination: Path) -> Path: | |
| destination.write_text(text or "", encoding="utf-8-sig") | |
| return destination | |
| def split_pages(text: str, expected: int) -> list[str]: | |
| if expected <= 1: | |
| return [text or ""] | |
| if PAGE_SEPARATOR in (text or ""): | |
| parts = (text or "").split(PAGE_SEPARATOR) | |
| else: | |
| parts = [text or ""] | |
| if len(parts) == expected: | |
| return parts | |
| if len(parts) > expected: | |
| head = parts[: expected - 1] | |
| tail = PAGE_SEPARATOR.join(parts[expected - 1 :]) | |
| return head + [tail] | |
| padded = list(parts) | |
| while len(padded) < expected: | |
| padded.append("") | |
| return padded | |