Update app.py
Browse files
app.py
CHANGED
|
@@ -4,24 +4,29 @@ from parrot import Parrot
|
|
| 4 |
import torch
|
| 5 |
import language_tool_python
|
| 6 |
import nltk
|
| 7 |
-
import time
|
| 8 |
|
|
|
|
| 9 |
nltk.download('punkt')
|
| 10 |
nltk.download('averaged_perceptron_tagger')
|
| 11 |
|
|
|
|
| 12 |
tool = language_tool_python.LanguageTool('en-US')
|
| 13 |
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_gpu=torch.cuda.is_available())
|
| 14 |
|
| 15 |
-
# Paraphrasing
|
| 16 |
def paraphrase_text(input_text, mode="Standard"):
|
| 17 |
if not input_text.strip():
|
| 18 |
return "", ""
|
| 19 |
|
| 20 |
-
# Grammar check
|
| 21 |
corrected = tool.correct(input_text)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if not para_phrases:
|
| 27 |
return corrected, "No paraphrase found."
|
|
@@ -37,7 +42,7 @@ def paraphrase_text(input_text, mode="Standard"):
|
|
| 37 |
|
| 38 |
return corrected, best
|
| 39 |
|
| 40 |
-
# Gradio
|
| 41 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 42 |
gr.Markdown("## 🚀 AI Paraphraser — Better Than QuillBot")
|
| 43 |
gr.Markdown("### Enter your text and select a paraphrasing mode")
|
|
@@ -53,6 +58,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 53 |
output_paraphrased = gr.Textbox(label="✨ Paraphrased Output", lines=3)
|
| 54 |
|
| 55 |
btn.click(fn=paraphrase_text, inputs=[input_text, mode], outputs=[output_corrected, output_paraphrased])
|
| 56 |
-
clear.click(lambda: ("", "", ""),
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
| 4 |
import torch
|
| 5 |
import language_tool_python
|
| 6 |
import nltk
|
|
|
|
| 7 |
|
| 8 |
+
# Download required NLTK data
|
| 9 |
nltk.download('punkt')
|
| 10 |
nltk.download('averaged_perceptron_tagger')
|
| 11 |
|
| 12 |
+
# Grammar and paraphrase tools
|
| 13 |
tool = language_tool_python.LanguageTool('en-US')
|
| 14 |
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_gpu=torch.cuda.is_available())
|
| 15 |
|
| 16 |
+
# Paraphrasing logic
|
| 17 |
def paraphrase_text(input_text, mode="Standard"):
|
| 18 |
if not input_text.strip():
|
| 19 |
return "", ""
|
| 20 |
|
|
|
|
| 21 |
corrected = tool.correct(input_text)
|
| 22 |
+
para_phrases = parrot.augment(
|
| 23 |
+
input_phrase=corrected,
|
| 24 |
+
diversity_ranker="levenshtein",
|
| 25 |
+
do_diverse=True,
|
| 26 |
+
max_return_phrases=5,
|
| 27 |
+
adequacy_threshold=0.90,
|
| 28 |
+
fluency_threshold=0.90
|
| 29 |
+
)
|
| 30 |
|
| 31 |
if not para_phrases:
|
| 32 |
return corrected, "No paraphrase found."
|
|
|
|
| 42 |
|
| 43 |
return corrected, best
|
| 44 |
|
| 45 |
+
# Gradio UI
|
| 46 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 47 |
gr.Markdown("## 🚀 AI Paraphraser — Better Than QuillBot")
|
| 48 |
gr.Markdown("### Enter your text and select a paraphrasing mode")
|
|
|
|
| 58 |
output_paraphrased = gr.Textbox(label="✨ Paraphrased Output", lines=3)
|
| 59 |
|
| 60 |
btn.click(fn=paraphrase_text, inputs=[input_text, mode], outputs=[output_corrected, output_paraphrased])
|
| 61 |
+
clear.click(lambda: ("", "", ""), outputs=[input_text, output_corrected, output_paraphrased])
|
| 62 |
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
demo.launch()
|