SoSa123456's picture
Create Utils.py
b77e4f5
'''
Utility functions for the Climate Change Radio Script Generator
'''
import nltk
import string
# Download the necessary NLTK data
nltk.download('punkt')
# Function to clean the generated paragraph
def clean_paragraph(entry):
paragraphs = entry.split('\n')
for i in range(len(paragraphs)):
split_sentences = nltk.tokenize.sent_tokenize(paragraphs[i], language='english')
if i == len(paragraphs) - 1 and split_sentences[:1][-1] not in string.punctuation:
paragraphs[i] = " ".join(split_sentences[:-1])
return capitalize_first_char("\n".join(paragraphs))
# Function to capitalize the first character of a string
def capitalize_first_char(entry):
for i in range(len(entry)):
if entry[i].isalpha():
return entry[:i] + entry[i].upper() + entry[i + 1:]
return entry