54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from parrot import Parrot
|
|
import torch
|
|
import warnings
|
|
warnings.filterwarnings("ignore")
|
|
import gradio as gr
|
|
from transformers import pipeline
|
|
from gradio.themes.utils import sizes
|
|
|
|
|
|
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
|
block_label_text_color = '#4D63FF',
|
|
block_title_text_color = '#4D63FF',
|
|
button_primary_text_color = '#4D63FF',
|
|
button_primary_background_fill='#FFFFFF',
|
|
button_primary_border_color='#4D63FF',
|
|
button_primary_background_fill_hover='#EDEFFF',
|
|
)
|
|
|
|
|
|
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_gpu=False)
|
|
|
|
|
|
def paraphraser(phrase):
|
|
para_phrases = parrot.augment(input_phrase=phrase)
|
|
|
|
total_para_phrase = ""
|
|
for para_phrase in para_phrases:
|
|
total_para_phrase += para_phrase[0]
|
|
total_para_phrase += "\r\n"
|
|
|
|
return total_para_phrase
|
|
|
|
|
|
with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
|
gr.Markdown("""
|
|
<div align='center' ><font size='60'>文本改述</font></div>
|
|
""")
|
|
with gr.Row():
|
|
with gr.Column():
|
|
box1 = gr.Textbox(label="文本")
|
|
with gr.Row():
|
|
button = gr.Button("提交", variant="primary")
|
|
clear = gr.Button("清除", variant="primary")
|
|
box2 = gr.Textbox(label="文本")
|
|
|
|
button.click(fn=paraphraser, inputs=box1, outputs=box2)
|
|
clear.click(lambda x: gr.update(value=''), [], [box1])
|
|
examples = gr.Examples(examples=[["Can you recommed some upscale restaurants in Newyork?"], ["What are the famous places we should not miss in Russia?"]], inputs=[box1], label="例子")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
demo.queue(concurrency_count=3)
|
|
demo.launch(server_name = "0.0.0.0")
|