File size: 804 Bytes
5e721a6
 
 
 
b165de5
 
5e721a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b165de5
 
 
 
 
 
 
 
 
5e721a6
b165de5
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
from parrot import Parrot
import torch
import warnings
warnings.filterwarnings("ignore")
import gradio as gr


''' 
uncomment to get reproducable paraphrase generations
def random_state(seed):
  torch.manual_seed(seed)
  if torch.cuda.is_available():
    torch.cuda.manual_seed_all(seed)

random_state(1234)
'''

#Init models (make sure you init ONLY once if you integrate this to your code)
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_gpu=False)


def generate_paraphrases(phrase):
    para_phrases = parrot.augment(input_phrase=phrase)
    return [para_phrase['phrase'] for para_phrase in para_phrases]

iface = gr.Interface(
    fn=generate_paraphrases, 
    inputs=gr.inputs.Textbox(lines=2, placeholder='Input Phrase...'), 
    outputs=gr.outputs.Textbox()
)

iface.launch()