Download src/normalizer.py from rzvn1/TRIEM_AI: direct link, hf CLI and curl.
- Browser
- Download file 550 Bytes
-
https://huggingface.co/spaces/rzvn1/TRIEM_AI/resolve/main/src/normalizer.py
- Command line
-
hf download hf://spaces/rzvn1/TRIEM_AI/src/normalizer.py
-
curl -L -o normalizer.py https://huggingface.co/spaces/rzvn1/TRIEM_AI/resolve/main/src/normalizer.py
550 Bytes
| import string | |
| import re | |
| def normalize_text(text): | |
| if not text: | |
| return "" | |
| # Lowercase conversion | |
| text = text.lower() | |
| # Remove punctuation | |
| text = text.translate(str.maketrans('', '', string.punctuation)) | |
| # Remove filler phrases | |
| fillers = ["how can i", "please tell", "can you", "tell me"] | |
| for filler in fillers: | |
| text = text.replace(filler, "") | |
| # Remove extra whitespace | |
| text = re.sub(r'\s+', ' ', text) | |
| # Strip whitespace | |
| text = text.strip() | |
| return text | |