benthecoder/news-summarizer
6
1from newspaper import Article2from newspaper import Config3import nltk4nltk.download('punkt')5 6from transformers import pipeline7import gradio as gr8from gradio.mix import Parallel, Series9 10 11def extract_article_text(url):12 USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'13 config = Config()14 config.browser_user_agent = USER_AGENT15 config.request_timeout = 1016 17 article = Article(url, config=config)18 article.download()19 article.parse()20 text = article.text21 return text22 23extractor = gr.Interface(extract_article_text, 'text', 'text')24summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")25 26sample_url = [['https://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/'],27 ['https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/'],28 ['https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/']]29 30desc = '''31 Let Hugging Face models summarize articles for you. 32 Note: Shorter articles generate faster summaries.33 This summarizer uses bart-large-cnn model by Facebook34 '''35 36iface = Series(extractor, summarizer, 37 inputs = gr.inputs.Textbox(38 lines = 2,39 label = 'URL'40 ),41 outputs = 'text',42 title = 'News Summarizer',43 theme = 'huggingface',44 description = desc,45 examples=sample_url)46 47iface.launch()