You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RedditVideoMakerBot/utils/posttextparser.py

36 lines
844 B

import os
import re
2 years ago
import time
from typing import List
import spacy
from utils.console import print_step
from utils.voice import sanitize_text
# working good
2 years ago
def posttextparser(obj, *, tried: bool = False) -> List[str]:
text: str = re.sub("\n", " ", obj)
try:
2 years ago
nlp = spacy.load("en_core_web_sm")
except OSError as e:
if not tried:
os.system("python -m spacy download en_core_web_sm")
2 years ago
time.sleep(5)
return posttextparser(obj, tried=True)
print_step(
"The spacy model can't load. You need to install it with the command \npython -m spacy download en_core_web_sm "
)
raise e
2 years ago
doc = nlp(text)
newtext: list = []
for line in doc.sents:
if sanitize_text(line.text):
newtext.append(line.text)
return newtext