Spaces:
Runtime error
Runtime error
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() | |