ky2k commited on
Commit
38de8f2
1 Parent(s): 2397be5

- added choice of several NN, added choice of several summarisation modes

Browse files
Files changed (1) hide show
  1. app.py +29 -14
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 is GPT-2 based Summarizer,
7
- works with English, Ukrainian, and Russian (and a few other languages too, it`s GPT-2 after all).
8
  """
9
 
 
 
10
 
11
- def start_fn(article_input: str) -> str:
 
12
  """
13
  GPT-2 based solution, input full text, output summarized text
 
 
14
  :param article_input:
15
  :return summarized article_output:
16
  """
17
- GPT2_model = TransformerSummarizer(transformer_type="GPT2", transformer_model_key="gpt2-medium")
18
- full = ''.join(GPT2_model(article_input, min_length=60))
19
- return full
 
 
 
 
 
 
 
 
 
 
 
 
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
- #face.launch(server_name="0.0.0.0", share=True)
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)