Spaces:
Sleeping
Sleeping
Download src/data/preprocessing.py from aviseth/fake-news-api: direct link, hf CLI and curl.
- Browser
- Download file 553 Bytes
-
https://huggingface.co/spaces/aviseth/fake-news-api/resolve/main/src/data/preprocessing.py
- Command line
-
hf download hf://spaces/aviseth/fake-news-api/src/data/preprocessing.py
-
curl -L -o preprocessing.py https://huggingface.co/spaces/aviseth/fake-news-api/resolve/main/src/data/preprocessing.py
553 Bytes
| import re | |
| import html | |
| from typing import List | |
| def clean_text(text: str) -> str: | |
| """Clean and normalize raw text — decodes HTML, strips URLs, normalizes whitespace.""" | |
| text = html.unescape(text) | |
| text = re.sub(r'http\S+', '', text) | |
| text = text.replace('\u201c', '"').replace( | |
| '\u201d', '"').replace('\u2013', '-') | |
| text = re.sub(r'\s+', ' ', text).strip() | |
| return text | |
| def preprocess_batch(texts: List[str]) -> List[str]: | |
| """Apply clean_text to a list of strings.""" | |
| return [clean_text(text) for text in texts] | |