File size: 1,653 Bytes
78b8ffd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ef2b35
78b8ffd
fb8b58e
78b8ffd
 
99a5b0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from newspaper import Article
from newspaper import Config

import gradio as gr
from gradio.mix import Parallel, Series

from transformers import pipeline

import nltk
nltk.download('punkt')

def extract_article_text(url):
  USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
  config = Config()
  config.browser_user_agent = USER_AGENT
  config.request_timeout = 10

  article = Article(url, config=config)
  article.download()
  article.parse()
  text = article.text
  return text

extractor = gr.Interface(extract_article_text, 'text', 'text')
summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")

sample_url = [['https://www.independent.co.uk/news/world/americas/us-politics/january-6-trump-biden-live-capitol-riot-b1988429.html'],
              ['https://edition.cnn.com/2022/01/06/asia/kazakhstan-fuel-protests-thursday-intl/index.html'],
         ['https://www.scmp.com/news/china/diplomacy/article/3162467/us-japan-boost-scientific-cooperation-defence-against?module=lead_hero_story&pgtype=homepage']]
           
description =  '''
        This application summarizes a news article based on the sentences used in the article. 
        Enter a news article link and submit for a summary. 
        A shorter news article produces a faster summary. A news article behind a paywall may produce an error.
        '''
  
iface = Series(extractor, summarizer, 
  inputs = gr.inputs.Textbox(
      lines = 2,
      label = 'URL'
  ),
  outputs = 'text',
  title = 'Extractive News Summarizer BART',
  theme = 'grass',
  description = description,
  examples=sample_url)
  
iface.launch()