This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install sumy | |
pip install streamlit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
nltk.download() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "export NLTK_DATA=<PATH-TO-YOUR-DATA> >> ~/.zshenv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{'source': {'id': None, 'name': None}, | |
'author': '', | |
'title': '', | |
'description': '', | |
'url': '', | |
'urlToImage': '', | |
'publishedAt': '', | |
'content': '', | |
'summary': ''} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
name = st.text_input('Enter Name') | |
if not name: | |
name = 'World' | |
st.write(f'Hello {name}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
streamlit run streamlit_example.py |
OlderNewer