Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from parrot import Parrot
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Initialize the Parrot model
|
| 6 |
+
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")
|
| 7 |
|
| 8 |
+
# Define paraphrasing function
|
| 9 |
+
def paraphrase_text(input_text):
|
| 10 |
+
if not input_text:
|
| 11 |
+
return ["Please enter text to paraphrase."]
|
| 12 |
+
|
| 13 |
+
# Generate paraphrases
|
| 14 |
+
paraphrases = parrot.augment(input_phrase=input_text, diversity_ranker="levenshtein", do_diverse=True)
|
| 15 |
+
|
| 16 |
+
if paraphrases:
|
| 17 |
+
return [p for p in paraphrases]
|
| 18 |
+
else:
|
| 19 |
+
return ["No paraphrase generated. Try another input."]
|
| 20 |
+
|
| 21 |
+
# Create UI with Gradio
|
| 22 |
+
interface = gr.Interface(
|
| 23 |
+
fn=paraphrase_text,
|
| 24 |
+
inputs=gr.Textbox(lines=3, placeholder="Enter text to paraphrase"),
|
| 25 |
+
outputs=gr.Textbox(lines=6),
|
| 26 |
+
title="Parrot Paraphraser",
|
| 27 |
+
description="An AI-powered paraphraser using the Parrot model. Enter a sentence, and it will generate multiple reworded versions."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
interface.launch()
|