Wootang01's picture
Update app.py
7ef2b35
raw history blame
No virus
1.65 kB
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()