File size: 1,997 Bytes
6a3ca39 b5e813c a3beb44 b5e813c 47e5004 b5e813c a3beb44 ff12162 47e5004 b5e813c a3beb44 b5e813c 42bc1c4 b5e813c a3beb44 b5e813c a3beb44 b5e813c ff12162 7e38706 ff12162 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import gradio as gr
from transformers import pipeline
from parrot import Parrot
import torch
import language_tool_python
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
tool = language_tool_python.LanguageTool('en-US')
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_gpu=False)
def paraphrase_text(input_text, mode="Standard"):
if not input_text.strip():
return "", ""
corrected = tool.correct(input_text)
para_phrases = parrot.augment(
input_phrase=corrected,
diversity_ranker="levenshtein",
do_diverse=True,
max_return_phrases=5,
adequacy_threshold=0.90,
fluency_threshold=0.90
)
if not para_phrases:
return corrected, "No paraphrase found."
best = para_phrases[0][0]
if mode == "Formal":
best = best.replace("gonna", "going to").replace("wanna", "want to")
elif mode == "Creative":
best = best.capitalize() + " π"
elif mode == "Concise":
best = " ".join(best.split()[:12]) + "..."
return corrected, best
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("## π AI Paraphraser β Better Than QuillBot")
gr.Markdown("### Enter your text and select a paraphrasing mode")
input_text = gr.Textbox(label="Original Text", placeholder="Type your sentence here...", lines=5)
mode = gr.Dropdown(["Standard", "Formal", "Creative", "Concise"], label="Paraphrasing Mode", value="Standard")
with gr.Row():
btn = gr.Button("π Paraphrase Now")
clear = gr.Button("π§Ή Clear")
output_corrected = gr.Textbox(label="π§Ή Corrected Input (Grammar fixed)", lines=3)
output_paraphrased = gr.Textbox(label="β¨ Paraphrased Output", lines=3)
btn.click(fn=paraphrase_text, inputs=[input_text, mode], outputs=[output_corrected, output_paraphrased])
clear.click(lambda: ("", "", ""), None, [input_text, output_corrected, output_paraphrased])
demo.launch()
|