Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from summarizer import TransformerSummarizer, Summarizer
|
4 |
+
|
5 |
+
title = "Summarizer"
|
6 |
+
description = """
|
7 |
+
This is a demo of a text summarization NN - based on GPT-2, XLNet, BERT,
|
8 |
+
works with English (and a few other languages too, these are SOTA NN after all).
|
9 |
+
"""
|
10 |
+
|
11 |
+
NN_OPTIONS_LIST = ["mean", "max", "min", "median"]
|
12 |
+
NN_LIST = ["GPT-2", "XLNet", "BERT"]
|
13 |
+
|
14 |
+
|
15 |
+
def start_fn(article_input: str, reduce_option="mean", model_type='GPT-2') -> str:
|
16 |
+
"""
|
17 |
+
GPT-2 based solution, input full text, output summarized text
|
18 |
+
:param model_type:
|
19 |
+
:param reduce_option:
|
20 |
+
:param article_input:
|
21 |
+
:return summarized article_output:
|
22 |
+
"""
|
23 |
+
if model_type == "GPT-2":
|
24 |
+
GPT2_model = TransformerSummarizer(transformer_type="GPT2", transformer_model_key="gpt2-medium",
|
25 |
+
reduce_option=reduce_option)
|
26 |
+
full = ''.join(GPT2_model(article_input, min_length=60))
|
27 |
+
return full
|
28 |
+
elif model_type == "XLNet":
|
29 |
+
XLNet_model = TransformerSummarizer(transformer_type="XLNet", transformer_model_key="xlnet-base-cased",
|
30 |
+
reduce_option=reduce_option)
|
31 |
+
full = ''.join(XLNet_model(article_input, min_length=60))
|
32 |
+
return full
|
33 |
+
|
34 |
+
elif model_type == "BERT":
|
35 |
+
BERT_model = Summarizer(reduce_option=reduce_option)
|
36 |
+
full = ''.join(BERT_model(article_input, min_length=60))
|
37 |
+
return full
|
38 |
+
|
39 |
+
|
40 |
+
face = gr.Interface(fn=start_fn,
|
41 |
+
inputs=[gr.inputs.Textbox(lines=2, placeholder="Paste article here.", label='Input Article'),
|
42 |
+
gr.inputs.Dropdown(NN_OPTIONS_LIST, label="Summarize mode"),
|
43 |
+
gr.inputs.Dropdown(NN_LIST, label="Selected NN")],
|
44 |
+
outputs=gr.inputs.Textbox(lines=2, placeholder="Summarized article here.", label='Summarized '
|
45 |
+
'Article'),
|
46 |
+
title=title,
|
47 |
+
description=description, )
|
48 |
+
face.launch(server_name="0.0.0.0", share=True
|