Skip to content

Instantly share code, notes, and snippets.

from sumy.parsers.html import HtmlParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lsa import LsaSummarizer as Summarizer
from sumy.nlp.stemmers import Stemmer
from sumy.utils import get_stop_words
import requests
def summarize_html(url:str, sentences_count:int=3, language:str='english') -> str:
parser = HtmlParser.from_url(url, Tokenizer(language))
pip install sumy
pip install streamlit
import nltk
nltk.download()
echo "export NLTK_DATA=<PATH-TO-YOUR-DATA> >> ~/.zshenv"
def summarize_html(url: str, sentences_count: int, language: str = 'english') -> str:
"""
Summarizes text from URL
Inputs
----------
url: URL for full text
sentences_count: specifies max number of sentences for return value
language: specifies language of text
def news_api_request(url: str, **kwargs) -> list:
"""
Sends GET request to News API endpoint
Inputs
----------
url: full URL for endpoint
kwargs: please refer to
News API documentations:
https://newsapi.org/docs/endpoints/
url = 'https://newsapi.org/v2/top-headlines/'
articles = news_api_request(url, apiKey=api_key, sortBy='publishedAt', country='us')
summaries = summarize_news_api(articles)
print(summaries[0])
{'source': {'id': None, 'name': None},
'author': '',
'title': '',
'description': '',
'url': '',
'urlToImage': '',
'publishedAt': '',
'content': '',
'summary': ''}
import streamlit as st
name = st.text_input('Enter Name')
if not name:
name = 'World'
st.write(f'Hello {name}')
streamlit run streamlit_example.py