Spaces:
Runtime error
Runtime error
Download src/preprocess.py from CoEdd/toxic-comment-detector: direct link, hf CLI and curl.
- Browser
- Download file 516 Bytes
-
https://huggingface.co/spaces/CoEdd/toxic-comment-detector/resolve/main/src/preprocess.py
- Command line
-
hf download hf://spaces/CoEdd/toxic-comment-detector/src/preprocess.py
-
curl -L -o preprocess.py https://huggingface.co/spaces/CoEdd/toxic-comment-detector/resolve/main/src/preprocess.py
516 Bytes
| def clean_text(text): | |
| import re | |
| import ftfy | |
| # Replace newlines, tabs, carriage returns with space | |
| text = re.sub(r'[\n\r\t]', ' ', text) | |
| # Strip leading and trailing whitespace | |
| text = text.strip() | |
| # Remove excessive spaces | |
| text = re.sub(r'\s+', ' ', text) | |
| # Fix encoding artifacts | |
| text = ftfy.fix_text(text) | |
| return text | |
| def preprocess_data(df): | |
| # Apply cleaning to the 'comment_text' column | |
| df['comment_text'] = df['comment_text'].apply(clean_text) | |
| return df |