Download app/ocr.py from drowzeys/keys-Auto-Receipts-Studio: direct link, hf CLI and curl.
- Browser
- Download file 588 Bytes
-
https://huggingface.co/drowzeys/keys-Auto-Receipts-Studio/resolve/main/app/ocr.py
- Command line
-
hf download hf://drowzeys/keys-Auto-Receipts-Studio/app/ocr.py
-
curl -L -o ocr.py https://huggingface.co/drowzeys/keys-Auto-Receipts-Studio/resolve/main/app/ocr.py
588 Bytes
| from __future__ import annotations | |
| from pathlib import Path | |
| from backends.base import OCRBackend, OCRResult | |
| def maybe_ocr(backend: OCRBackend | None, path: Path) -> OCRResult | None: | |
| if backend is None: | |
| sidecar = path.with_suffix(".txt") | |
| if sidecar.is_file(): | |
| return OCRResult(text=sidecar.read_text(encoding="utf-8", errors="replace"), engine="sidecar") | |
| if path.suffix.lower() == ".txt": | |
| return OCRResult(text=path.read_text(encoding="utf-8", errors="replace"), engine="plaintext") | |
| return None | |
| return backend.ocr(path) | |