text_plain_output_1.png
from newspaper import Article

from transformers import ProphetNetForConditionalGeneration, ProphetNetTokenizer, pipeline

from urllib.request import urlopen

import feedparser

model = ProphetNetForConditionalGeneration.from_pretrained('microsoft/prophetnet-large-uncased-cnndm')
tokenizer = ProphetNetTokenizer.from_pretrained('microsoft/prophetnet-large-uncased-cnndm')

def prophetnet_summarizer(text, config=None):
    if config:
        model = ProphetNetForConditionalGeneration.from_pretrained('microsoft/prophetnet-large-uncased')
        model.config.update(config)
    else:
        model = ProphetNetForConditionalGeneration.from_pretrained('microsoft/prophetnet-large-uncased')
    tokenizer = ProphetNetTokenizer.from_pretrained('microsoft/prophetnet-large-uncased')
    inputs = tokenizer(text, return_tensors='pt')
    summary_ids = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'], num_beams=4, length_penalty=2.0, max_length=200, min_length=100, no_repeat_ngram_size=3)
    summary = tokenizer.batch_decode(summary_ids, skip_special_tokens=True)
    return summary
def prophetnet_summarizer(text, config=None):
    if config:
        model = ProphetNetForConditionalGeneration.from_pretrained('microsoft/prophetnet-large-uncased')
        model.config.update(config)
    else:
        model = ProphetNetForConditionalGeneration.from_pretrained('microsoft/prophetnet-large-uncased')
    tokenizer = ProphetNetTokenizer.from_pretrained('microsoft/prophetnet-large-uncased')
    inputs = tokenizer(text, return_tensors='pt')
    summary_ids = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'], num_beams=4, length_penalty=2.0, max_length=200, min_length=100, no_repeat_ngram_size=3)
    summary = tokenizer.batch_decode(summary_ids, skip_special_tokens=True)
    return summary

site = 'https://news.google.com/rss/search?q=politics'
op = urlopen(site)
rd = op.read()
op.close()
sp_page = soup(rd, 'xml')
news_list = sp_page.find_all('item')

rss_feed = feedparser.parse('https://www.aljazeera.com/xml/rss/all.xml')
news_list = rss_feed.entries

c = 0
for i, news in enumerate(news_list):
    c += 1
    print(f'News Article {i + 1}:')
    print('Title: ', news.title)
    print('News Link: ', news.link)
    news_data = Article(news.link)
    news_data.download()
    news_data.parse()
    news_text = news_data.text
    summary = prophetnet_summarizer(news_text)
    print('News Summary: ', summary[0].capitalize())
    print('News Poster Link: ', news_data.top_image)
    print('-' * 60)
    if c >= 2:
        break