SummarizeLink / app.py
mohitmayank's picture
initial version
81b2b07
raw
history blame
1.86 kB
# import
from tensorflow.python.keras.utils.generic_utils import default
import streamlit as st
from newspaper import Article
from transformers import pipeline
st.set_page_config(layout="wide", page_title="SummarizeLink")
# load the summarization model
@st.cache(allow_output_mutation=True)
def load_summarize_model():
# model = pipeline("summarization", model='sshleifer/distilbart-cnn-12-6')
model = pipeline("summarization")
return model
summ = load_summarize_model()
# define functions
def download_and_parse_article(url):
article = Article(url)
article.download()
article.parse()
return article.text
# define the app
st.title("SummarizeLink")
st.text("Paste any article link below and click on the 'Summarize Text' button to get the summarized data")
# st.subheader("This application is using HuggingFace's transformers pre-trained model for text summarization.")
link = st.text_area('Paste your link here...', "https://towardsdatascience.com/a-guide-to-the-knowledge-graphs-bfb5c40272f1", height=50)
button = st.button("Summarize")
max_lengthy = st.sidebar.slider('Max summary length', min_value=30, max_value=700, value=100, step=10)
# num_beamer = st.sidebar.slider('Speed vs quality of Summary (1 is fastest but less accurate)', min_value=1, max_value=8, value=4, step=1)
with st.spinner("Summarizing..."):
if button and link:
text = download_and_parse_article(link) # get the text
summary = summ(text,
truncation=True,
max_length = max_lengthy,
min_length = 50,
num_beams=5,
do_sample=True,
early_stopping=True,
repetition_penalty=1.5,
length_penalty=1.5)[0]
st.write(summary['summary_text'])