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