ganeshkamath89 commited on
Commit
e9afa29
·
verified ·
1 Parent(s): 937dca2

Adding pretty print and replacing wikipedia article URLs with news URLs

Browse files
Files changed (1) hide show
  1. app.py +38 -31
app.py CHANGED
@@ -2,40 +2,47 @@ from newspaper import Article, Config
2
  from transformers import pipeline
3
  import gradio as gr
4
 
 
5
  def extract_article_summary(url):
6
- USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
7
- config = Config()
8
- config.browser_user_agent = USER_AGENT
9
- config.request_timeout = 10
10
-
11
- article = Article(url, config=config)
12
- article.download()
13
- article.parse()
14
- text = article.text
15
- summarizer = pipeline("summarization", model = "facebook/bart-large-cnn")
16
- return summarizer(text)[0]['summary_text']
17
-
18
- sample_url = [['https://en.wikipedia.org/wiki/AMD'],
19
- ['https://en.wikipedia.org/wiki/Semiconductor_industry'],
20
- ['https://en.wikipedia.org/wiki/Artificial_intelligence']]
21
-
22
- desc = '''
 
 
 
 
 
 
 
 
 
23
  Let Hugging Face models summarize articles for you.
24
  Note: Shorter articles generate faster summaries.
25
  This summarizer uses bart-large-cnn model by Facebook
26
- '''
27
-
28
- demo = gr.Interface (
29
- extract_article_summary,
30
- inputs = gr.Textbox(
31
- lines = 2,
32
- label = 'URL'
33
- ),
34
- outputs = 'text',
35
- title = 'News Summarizer',
36
- theme = 'huggingface',
37
- description = desc,
38
- examples=sample_url
39
  )
40
 
41
- demo.launch()
 
2
  from transformers import pipeline
3
  import gradio as gr
4
 
5
+
6
  def extract_article_summary(url):
7
+ USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0"
8
+ config = Config()
9
+ config.browser_user_agent = USER_AGENT
10
+ config.request_timeout = 10
11
+
12
+ article = Article(url, config=config)
13
+ article.download()
14
+ article.parse()
15
+ text = article.text
16
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
17
+ return summarizer(text)[0]["summary_text"]
18
+
19
+
20
+ sample_url = [
21
+ [
22
+ "https://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/"
23
+ ],
24
+ [
25
+ "https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/"
26
+ ],
27
+ [
28
+ "https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/"
29
+ ],
30
+ ]
31
+
32
+ desc = """
33
  Let Hugging Face models summarize articles for you.
34
  Note: Shorter articles generate faster summaries.
35
  This summarizer uses bart-large-cnn model by Facebook
36
+ """
37
+
38
+ demo = gr.Interface(
39
+ extract_article_summary,
40
+ inputs=gr.Textbox(lines=2, label="URL"),
41
+ outputs="text",
42
+ title="News Summarizer",
43
+ theme="huggingface",
44
+ description=desc,
45
+ examples=sample_url,
 
 
 
46
  )
47
 
48
+ demo.launch()