import gradio as gr from transformers import pipeline import re # Function to clean the output by truncating at the last full sentence and formatting paragraphs def clean_output(text): # Remove unwanted symbols and replace them with appropriate punctuation or space text = re.sub(r'\.{2,}', '.', text) # Replace sequences of more than one period with a single period text = re.sub(r'[:\-]+', '', text) # Remove colons and dashes text = re.sub(r'[()]+', '', text) # Remove parentheses text = re.sub(r'\s+', ' ', text) # Replace excessive spaces text = re.sub(r'[^\S\n]+', ' ', text) # Remove non-visible spaces like tabs # Ensure the text ends with a full sentence if '.' in text: text = text[:text.rfind('.')+1] # Truncate at the last full sentence # Add paragraph breaks by splitting sentences into paragraphs sentences = re.split(r'(?