import re def clean_text(text): # Remove extra spaces and newlines text = re.sub(r'\s+', ' ', text) # Remove any unwanted special characters text = re.sub(r'[^\w\s.,;?!-]', '', text) # Optional: Remove redundant spaces around punctuation text = re.sub(r'\s([?.!.,;])', r'\1', text) # Capitalize the first letter of each sentence text = re.sub(r'(?