Spaces:
Runtime error
Runtime error
add app.py
Browse files- .gitignore +3 -0
- app.py +42 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.venv
|
2 |
+
.vscode
|
3 |
+
flagged
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from parrot import Parrot
|
4 |
+
import warnings
|
5 |
+
|
6 |
+
warnings.filterwarnings("ignore")
|
7 |
+
|
8 |
+
"""
|
9 |
+
uncomment to get reproducable paraphrase generations
|
10 |
+
def random_state(seed):
|
11 |
+
torch.manual_seed(seed)
|
12 |
+
if torch.cuda.is_available():
|
13 |
+
torch.cuda.manual_seed_all(seed)
|
14 |
+
|
15 |
+
random_state(1234)
|
16 |
+
"""
|
17 |
+
|
18 |
+
# Init models (make sure you init ONLY once if you integrate this to your code)
|
19 |
+
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")
|
20 |
+
|
21 |
+
|
22 |
+
def generate_paraphases(phrase):
|
23 |
+
para_phrases = parrot.augment(
|
24 |
+
input_phrase=phrase, use_gpu=False, max_return_phrases=10
|
25 |
+
)
|
26 |
+
return "\n".join(["- " + item[0] for item in para_phrases])
|
27 |
+
|
28 |
+
|
29 |
+
input_textbox = gr.Textbox(label="Type your sentence here", lines=5)
|
30 |
+
output_textbox = gr.Textbox(label="Paraphrases", lines=10)
|
31 |
+
|
32 |
+
demo = gr.Interface(
|
33 |
+
fn=generate_paraphases,
|
34 |
+
inputs=input_textbox,
|
35 |
+
outputs=output_textbox,
|
36 |
+
examples=[
|
37 |
+
"Can you recommed some upscale restaurants in Newyork?",
|
38 |
+
"What are the famous places we should not miss in Russia?",
|
39 |
+
],
|
40 |
+
)
|
41 |
+
|
42 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.0.14
|
2 |
+
protobuf==3.20.1
|
3 |
+
git+https://github.com/PrithivirajDamodaran/Parrot_Paraphraser.git
|