import warnings import random import torch from parrot import Parrot # Suppress warnings warnings.filterwarnings("ignore") os.environ['TRANSFORMERS_NO_ADVISORY_WARNINGS'] = '1' # Set random state for reproducibility def random_state(seed): torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed_all(1234) # Initialize Parrot model parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5") # Function to paraphrase a single sentence def paraphrase_sentence(sentence): paraphrases = parrot.augment(input_phrase=sentence, max_return_phrases=10, max_length=100, adequacy_threshold=0.75, fluency_threshold=0.75) if paraphrases: return random.choice(paraphrases)[0] # Select a random paraphrase return sentence # Return the original sentence if no paraphrase is available # Function to split text by periods (full stops) def split_text_by_fullstop(text): sentences = [sentence.strip() for sentence in text.split('.') if sentence] # Split and remove empty strings return sentences # Main function to process and paraphrase text by splitting at periods def process_text_by_fullstop(text): sentences = split_text_by_fullstop(text) # Split text into sentences by full stops paraphrased_sentences = [paraphrase_sentence(sentence + '.') for sentence in sentences] # Paraphrase each sentence return ' '.join(paraphrased_sentences) # Join paraphrased sentences back into a single text # Function to copy output text to the clipboard def copy_to_clipboard(output_text): # JavaScript code to copy the output text to the clipboard return f""" """ # Gradio interface function def generate_content(input_text): paraphrased_text = process_text_by_fullstop(input_text) return paraphrased_text # Gradio Interface with new layout with gr.Blocks() as demo: # Adding a logo and title gr.HTML("""