Spaces:
Runtime error
Runtime error
File size: 1,058 Bytes
e907871 |
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 |
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=10
)
return "\n".join(["- " + item[0] for item in para_phrases])
input_textbox = gr.Textbox(label="Type your sentence here", lines=5)
output_textbox = gr.Textbox(label="Paraphrases", lines=10)
demo = gr.Interface(
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()
|