File size: 1,087 Bytes
bba5c68
 
d28d703
 
f3d27a8
f9a43d0
bba5c68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4be9250
 
bba5c68
 
4be9250
bba5c68
 
 
 
 
4be9250
bba5c68
 
 
 
 
 
f3d27a8
 
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
from newspaper import Article
from newspaper import Config
import gradio as gr
from gradio.mix import Parallel, Series



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.cp24.com/news/ontario-reports-481-new-covid-19-cases-1-death-1.5667950'],
]

desc =  '''
         the news summarizer uses bart-large-cnn model by Facebook to summarize the text of the article.
        '''

iface = Series(extractor, summarizer, 
  inputs = gr.inputs.Textbox(
      lines = 2,
      label = 'Enter URL below'
  ),
  outputs = 'text',
  title = 'News Summarizer',
  theme = 'huggingface',
  description = desc,
  examples=sample_url)

iface.launch()