parrot-t5-test / app.py
king007's picture
Update app.py
455780a
raw
history blame contribute delete
No virus
1.11 kB
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()