from newspaper import Article from newspaper import Config import nltk nltk.download('punkt') from transformers import pipeline 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://parstoday.com/en/news/iran-i163822-iran_condemns_terrorist_attack_in_pakistan_reaffirms_need_to_fight_terrorism_across_region/'], ['https://parstoday.com/en/news/west_asia-i163734-ansarullah_yemenis_entitled_to_avenge_nation%E2%80%99s_sufferings_inflicted_due_to_war_siege/'], ['https://parstoday.com/en/news/west_asia-i163684-saudi_led_warplanes_intensify_airstrikes_against_yemeni_capital/']] desc = ''' Let Hugging Face models summarize articles for you. Note: Shorter articles generate faster summaries. This summarizer uses bart-large-cnn model by Facebook ''' iface = Series(extractor, summarizer, inputs = gr.inputs.Textbox( lines = 2, label = 'URL' ), outputs = 'text', title = 'News Summarizer', theme = 'huggingface', description = desc, examples=sample_url) iface.launch()