File size: 1,105 Bytes
44ed0fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6829598
44ed0fa
455780a
44ed0fa
 
4ff80d9
 
44ed0fa
6829598
 
 
44ed0fa
 
 
4ff80d9
 
 
 
44ed0fa
 
 
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
import gradio as gr

from parrot import Parrot
import warnings

warnings.filterwarnings("ignore")

""" 
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")


def generate_paraphases(phrase):
    para_phrases = parrot.augment(
        input_phrase=phrase, use_gpu=False, max_return_phrases=5
    )
    return "\n\n".join(["" + item[0] for item in para_phrases])


input_textbox = gr.Textbox(label="", lines=5)
output_textbox = gr.Textbox(label="", lines=10)

demo = gr.Interface(theme="huggingface",
    description="description",
    layout="vertical",
    fn=generate_paraphases,
    inputs=input_textbox,
    outputs=output_textbox,
    # examples=[
    #     "Can you recommed some upscale restaurants in Newyork?",
    #     "What are the famous places we should not miss in Russia?",
    # ],
)

demo.launch()