Download app/utils/text_cleaning.py from acpcchatbotadmin/acpcchatbot_testing_first: direct link, hf CLI and curl.
- Browser
- Download file 457 Bytes
-
https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/utils/text_cleaning.py
- Command line
-
hf download hf://spaces/acpcchatbotadmin/acpcchatbot_testing_first/app/utils/text_cleaning.py
-
curl -L -o text_cleaning.py https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/utils/text_cleaning.py
457 Bytes
| import re | |
| def clean_pdf_text(text: str) -> str: | |
| """Normalize text extracted from PDF chunks.""" | |
| # Collapse multiple whitespace into single space | |
| text = re.sub(r"[ \t]+", " ", text) | |
| # Collapse more than 2 consecutive newlines | |
| text = re.sub(r"\n{3,}", "\n\n", text) | |
| # Remove null bytes and control characters (except newlines/tabs) | |
| text = re.sub(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]", "", text) | |
| return text.strip() | |