Spaces:
Sleeping
Sleeping
Update app.py
Browse files22 unmodified lines2324252627282930313233343536373839404142434411 unmodified lines56575859606122 unmodified linesreturn ' '.join(cleaned_sentences)def process_text(text):"""Insert a newline after periods, except for titles and ." """# Split text into wordswords = text.split()processed_words = []for i, word in enumerate(words):# Check if the word is a title (e.g., Mr., Mrs.)if word in TITLES:processed_words.append(word)# Check if the word ends with a period and is not followed by a quoteelif word.endswith('.') and not word.endswith('."'):processed_words.append(word + '\n')else:processed_words.append(word)return ' '.join(processed_words)def combine_dataset_texts(dataset_name, split, text_column):try:11 unmodified linescleaned_text = clean_text(combined_text)# Process the text: insert newlines after periods, except for titles and ."processed_text = process_text(cleaned_text)# Create a temporary file22 unmodified lines2324252627282930313233343536373839404142434445464748495051525311 unmodified lines6566676869707122 unmodified linesreturn ' '.join(cleaned_sentences)def process_text(text):"""Insert a newline after periods, except for titles and ."Also replace '### Simplified Version' with 'Chapter N' where N increments."""# Split text into wordswords = text.split()processed_text = ""chapter_counter = 1 # Initialize chapter counterfor i, word in enumerate(words):# Check if the word is a title (e.g., Mr., Mrs.)if word in TITLES:processed_text += word + " "# Check if the word ends with a period and is not followed by a quoteelif word.endswith('.') and not word.endswith('."'):processed_text += word + "\n"# Replace '### Simplified Version' with 'Chapter N'elif word == "###" and i + 2 < len(words) and words[i + 1] == "Simplified" and words[i + 2] == "Version":processed_text += f"Chapter {chapter_counter} "chapter_counter += 1 # Increment chapter counterwords[i + 1] = "" # Skip the next two wordswords[i + 2] = ""else:processed_text += word + " "# Remove trailing spaces and newlinesreturn processed_text.strip()def combine_dataset_texts(dataset_name, split, text_column):try:11 unmodified linescleaned_text = clean_text(combined_text)# Process the text: insert newlines after periods, except for titles and ."# Also replace '### Simplified Version' with 'Chapter N'processed_text = process_text(cleaned_text)# Create a temporary file
app.py+16-6