Wootang01 commited on
Commit
78b8ffd
·
1 Parent(s): dad38e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from newspaper import Article
2
+ from newspaper import Config
3
+
4
+ import gradio as gr
5
+ from gradio.mix import Parallel, Series
6
+
7
+ from transformers import pipeline
8
+
9
+ import nltk
10
+ nltk.download('punkt')
11
+
12
+ def extract_article_text(url):
13
+ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
14
+ config = Config()
15
+ config.browser_user_agent = USER_AGENT
16
+ config.request_timeout = 10
17
+
18
+ article = Article(url, config=config)
19
+ article.download()
20
+ article.parse()
21
+ text = article.text
22
+ return text
23
+
24
+ extractor = gr.Interface(extract_article_text, 'text', 'text')
25
+ summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
26
+
27
+ sample_url = [['https://www.independent.co.uk/news/world/americas/us-politics/january-6-trump-biden-live-capitol-riot-b1988429.html'],
28
+ ['https://edition.cnn.com/2022/01/06/asia/kazakhstan-fuel-protests-thursday-intl/index.html'],
29
+ ['https://www.scmp.com/news/china/diplomacy/article/3162467/us-japan-boost-scientific-cooperation-defence-against?module=lead_hero_story&pgtype=homepage']]
30
+
31
+ description = '''
32
+ This application summarizes a news article based on the sentences used in the article.
33
+ Enter a news article link and submit for a summary.
34
+ A shorter news article produces a faster summary. A news article behind a paywall may produce an error.
35
+ '''
36
+
37
+ iface = Series(extractor, summarizer,
38
+ inputs = gr.inputs.Textbox(
39
+ lines = 2,
40
+ label = 'URL'
41
+ ),
42
+ outputs = 'text',
43
+ title = 'Extractive News Summarizer',
44
+ theme = 'grass',
45
+ description = desc,
46
+ examples=sample_url)
47
+
48
+ iface.launch()