import numpy as np import pandas as pd import re import torch import gradio as gr from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base") model = AutoModelForSeq2SeqLM.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base") tokenizer_gen_title = AutoTokenizer.from_pretrained("Ateeqq/news-title-generator") model_gen_title = AutoModelForSeq2SeqLM.from_pretrained("Ateeqq/news-title-generator") def generate_title(input_text): #Generate a title for input text with Ateeq model input_ids = tokenizer_gen_title.encode(input_text, return_tensors="pt") #Tokenize input text #input_ids = input_ids.to('cuda') #Send tokenized inputs to gpu output = model_gen_title.generate(input_ids, max_new_tokens=100, do_sample=True, temperature=0.8, top_k = 20 ) decoded_text = tokenizer_gen_title.decode(output[0], skip_special_tokens=True) return decoded_text def split_into_sentences(paragraph): #For paraphraser - return a list of sentences from input para # Split sentences after period. Retains \n if part of the text, but not included in model output sentence_endings = r'(?") #titles_list.append ("") #space after each title return (titles_list, paraphrased_text) # Return paraphrased text after printing three titles above iface = gr.Interface(fn=paraphrase, inputs=[gr.Textbox(label="Paste text in the input box and press 'Submit'.", lines=10), "checkbox", gr.Slider(0.1, 2, 0.8)], outputs=[gr.HTML(label="Titles:"), gr.Textbox(label="Rephrased text:", lines=15)], title="AI Paraphraser with Title Generator", description="Sentencet-to-sentence rewording backed with GPT-3.5 training set", article="

AI Paraphraser and Title Generator

  • Each sentence is rephrased separately without context.
  • Temperature: Increase value for more creative rewordings. Higher values may corrupt the sentence. Reset value after pressing 'Clear'
  • Beam search: Try for safer and conservative rephrasing.
  • Models:

  • Training set derived by using Chat-GPT3.5. No competition intended.
  • Original models: humarin/chatgpt_paraphraser_on_T5_base and Ateeq_news_title_generator. Deployment code modified for long text inputs.
  • Parameter details:

  • For rephraser: Beam search: No. of beams = 20, no_repeat_ngram_size=4, do_sample=True.
  • For title generator: do_sample=True, temperature=0.8, top_k = 20
  • ", flagging_mode='never' ) iface.launch()