g3casey commited on
Commit
20b6df0
1 Parent(s): 36c9b26

Changing to paste in text for input since the wikipedia api doesn't work.

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -3,15 +3,16 @@ import wikipedia
3
  from transformers import pipeline
4
  import os
5
 
6
- ## Setting to use the 0th GPU
7
  os.environ["CUDA_VISIBLE_DEVICES"] = "0"
8
 
 
9
  def summarize(text):
10
- ## Setting to use the bart-large-cnn model for summarization
11
  summarizer = pipeline("summarization")
12
 
13
- ## To use the t5-base model for summarization:
14
- ## summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf")
15
 
16
  summary_text = summarizer(text, max_length=100, min_length=5, do_sample=False)[0]['summary_text']
17
  print(f'Length of initial text: {len(text)}')
@@ -19,6 +20,7 @@ def summarize(text):
19
  print(summary_text)
20
  return summary_text
21
 
 
22
  def greet(name):
23
  return "Hello " + name.orig_name + "!!"
24
 
@@ -32,9 +34,9 @@ def search_wiki(text):
32
 
33
 
34
  def get_wiki(search_term):
35
- text = wikipedia.summary(search_term)
36
- orig_text_len = len(text)
37
- text = summarize(text)
38
  sum_length = len(text)
39
  return [text, orig_text_len, sum_length]
40
 
@@ -49,9 +51,9 @@ out_sum_text_len = gr.Number(label='Summarized Text Length')
49
 
50
  iface = gr.Interface(fn=get_wiki,
51
  inputs=gr.Textbox(lines=50, placeholder="Wikipedia search term here...", label='Search Term'),
52
- outputs=[out_sum_text,out_orig_test_len,out_sum_text_len],
53
  title='Article Summary',
54
  description='Paste in an article and it will be summarized',
55
  sample_inputs='guardians of the galaxy'
56
- )
57
- iface.launch() # To create a public link, set `share=True` in `launch()`.
 
3
  from transformers import pipeline
4
  import os
5
 
6
+ # Setting to use the 0th GPU
7
  os.environ["CUDA_VISIBLE_DEVICES"] = "0"
8
 
9
+
10
  def summarize(text):
11
+ # Setting to use the bart-large-cnn model for summarization
12
  summarizer = pipeline("summarization")
13
 
14
+ # To use the t5-base model for summarization:
15
+ # summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf")
16
 
17
  summary_text = summarizer(text, max_length=100, min_length=5, do_sample=False)[0]['summary_text']
18
  print(f'Length of initial text: {len(text)}')
 
20
  print(summary_text)
21
  return summary_text
22
 
23
+
24
  def greet(name):
25
  return "Hello " + name.orig_name + "!!"
26
 
 
34
 
35
 
36
  def get_wiki(search_term):
37
+ # text = wikipedia.summary(search_term)
38
+ orig_text_len = len(search_term)
39
+ text = summarize(search_term)
40
  sum_length = len(text)
41
  return [text, orig_text_len, sum_length]
42
 
 
51
 
52
  iface = gr.Interface(fn=get_wiki,
53
  inputs=gr.Textbox(lines=50, placeholder="Wikipedia search term here...", label='Search Term'),
54
+ outputs=[out_sum_text, out_orig_test_len, out_sum_text_len],
55
  title='Article Summary',
56
  description='Paste in an article and it will be summarized',
57
  sample_inputs='guardians of the galaxy'
58
+ )
59
+ iface.launch() # To create a public link, set `share=True` in `launch()`.