Spaces:
Runtime error
Runtime error
Download replace_explitives.py from mskov/Speech-Trigger-Detection: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/mskov/Speech-Trigger-Detection/resolve/218afdcbf6dd9f92492013bbcc883b645e6e523a/replace_explitives.py
- Command line
-
hf download hf://spaces/mskov/Speech-Trigger-Detection@218afdcbf6dd9f92492013bbcc883b645e6e523a/replace_explitives.py
-
curl -L -o replace_explitives.py https://huggingface.co/spaces/mskov/Speech-Trigger-Detection/resolve/218afdcbf6dd9f92492013bbcc883b645e6e523a/replace_explitives.py
857 Bytes
| import nltk | |
| from nltk.tokenize import word_tokenize, sent_tokenize | |
| import re | |
| nltk.download('punkt') # For tokenization | |
| nltk.download('averaged_perceptron_tagger') # For POS tagging (optional) | |
| def sub_explitives(textfile, selection): | |
| replacetext = "person" | |
| # text = word_tokenize(textfile) | |
| # print(text) | |
| # sentences = sent_tokenize(textfile) | |
| if selection == "B": | |
| target_word = r"\bbitch\b" | |
| elif selection == "N": | |
| target_word = r"\bnigg\b" | |
| elif selection == "all": | |
| target_word = r"\bshit\b" | |
| else: | |
| target_word = None | |
| print("selection:", selection, "target_word:", target_word) | |
| if target_word: | |
| print("target word was found, ", target_word) | |
| print(text) | |
| textfile = re.sub(target_word, replacetext, textfile, flags=re.IGNORECASE) | |
| return textfile |