Spaces:
Runtime error
Runtime error
Download app/parser/chunk.py from zinoubm/openpdf-backend: direct link, hf CLI and curl.
- Browser
- Download file 472 Bytes
-
https://huggingface.co/spaces/zinoubm/openpdf-backend/resolve/main/app/parser/chunk.py
- Command line
-
hf download hf://spaces/zinoubm/openpdf-backend/app/parser/chunk.py
-
curl -L -o chunk.py https://huggingface.co/spaces/zinoubm/openpdf-backend/resolve/main/app/parser/chunk.py
472 Bytes
| from textwrap3 import dedent | |
| from unidecode import unidecode | |
| import re | |
| def chunk_text(text, max_size=4000): | |
| paragraphs = dedent(text) | |
| ascii_paragraphs = re.findall(r"[^.?!]+[(\.)?!]", unidecode(paragraphs)) | |
| chuncks = [] | |
| chunck = "" | |
| for sentence in ascii_paragraphs: | |
| if len(chunck) + len(sentence) < max_size: | |
| chunck += sentence | |
| else: | |
| chuncks.append(chunck.strip()) | |
| chunck = "" | |
| return chuncks | |