From 668c6024c9f2cf5486ad02f18118ce945301b41c Mon Sep 17 00:00:00 2001 From: songw Date: Mon, 17 Apr 2023 14:31:50 +0800 Subject: [PATCH] add bart-large-cnn --- Dockerfile | 10 ++++++++++ app.py | 41 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +++ 3 files changed, 54 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f53e5eb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.8.13 + +WORKDIR /app + +COPY . /app + +RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple +RUN pip install -r requirements.txt + +CMD ["python", "app.py"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..51e14b9 --- /dev/null +++ b/app.py @@ -0,0 +1,41 @@ +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', +) + +summarizer = pipeline("summarization", model="facebook/bart-large-cnn") + +def summarize(text): + result = summarizer(text, max_length=130, min_length=30, do_sample=False) + + return result[0].get('summary_text') + + +with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo: + gr.Markdown(""" +
文本摘要
+ """) + 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=summarize, inputs=box1, outputs=box2) + examples = gr.Examples(examples=["The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct."], inputs=[box1]) + + +if __name__ == "__main__": + demo.queue(concurrency_count=3) + demo.launch(server_name = "0.0.0.0", server_port = 7028) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dfaa0e1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +gradio == 3.27.0 +transformers +torch