Download infra/local_extractor.py from ZeloTech/zelotech: direct link, hf CLI and curl.
- Browser
- Download file 988 Bytes
-
https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/infra/local_extractor.py
- Command line
-
hf download hf://spaces/ZeloTech/zelotech/infra/local_extractor.py
-
curl -L -o local_extractor.py https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/infra/local_extractor.py
988 Bytes
| from services.ocr import ocr_image_path | |
| from services.pdf_utils import extract_pdf_text | |
| class TesseractExtractor: | |
| """Extracao local de texto. | |
| PDF: usa a camada de texto quando existe (instantaneo, via PyMuPDF) e so | |
| cai para OCR (Tesseract) nas paginas que forem escaneadas. | |
| Imagem (JPG/PNG): vai direto para OCR. | |
| Retorna o texto cru, sem nenhum tratamento, como voce pediu. | |
| """ | |
| def __init__(self, lang: str = "por", dpi: int = 300, min_chars_per_page: int = 20): | |
| self._lang = lang | |
| self._dpi = dpi | |
| self._min_chars = min_chars_per_page | |
| def extract(self, path: str, kind: str) -> str: | |
| if kind == "pdf": | |
| return extract_pdf_text( | |
| path, dpi=self._dpi, min_chars_per_page=self._min_chars, lang=self._lang | |
| ) | |
| if kind == "image": | |
| return ocr_image_path(path, lang=self._lang).strip() | |
| raise ValueError(f"kind nao suportado: {kind!r}") | |