Spaces:
Running
Running
Download processing/texts.py from mapslab/AISVIZ-BOT: direct link, hf CLI and curl.
- Browser
- Download file 529 Bytes
-
https://huggingface.co/spaces/mapslab/AISVIZ-BOT/resolve/main/processing/texts.py
- Command line
-
hf download hf://spaces/mapslab/AISVIZ-BOT/processing/texts.py
-
curl -L -o texts.py https://huggingface.co/spaces/mapslab/AISVIZ-BOT/resolve/main/processing/texts.py
529 Bytes
| import re | |
| def clean_text(text: str) -> str: | |
| """ | |
| Clean the text by removing unwanted characters while preserving document structure. | |
| """ | |
| text = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]', '', text) # remove control chars (keep \n \t \r) | |
| text = re.sub(r'\r\n?', '\n', text) # normalize line endings | |
| text = re.sub(r'\n{3,}', '\n\n', text) # collapse excessive newlines | |
| text = re.sub(r'[^\S\n]{3,}', ' ', text) # collapse excessive spaces (not newlines) | |
| return text.strip() | |