Spaces:
Runtime error
Runtime error
File size: 2,481 Bytes
81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 f9583a4 81b2b07 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# import
from tensorflow.python.keras.utils.generic_utils import default
import streamlit as st
from newspaper import Article
from transformers import pipeline
# set config
st.set_page_config(layout="wide", page_title="SummarizeLink")
# load the summarization model (cache for faster loading)
@st.cache(allow_output_mutation=True)
def load_summarize_model():
# model = pipeline("summarization", model='sshleifer/distilbart-cnn-12-6')
model = pipeline("summarization")
return model
# loading the model
summ = load_summarize_model()
# define the down functions
def download_and_parse_article(url):
"""Downloads and parses an article from a URL.
Parameters
----------
url : str
The URL of the article to download and parse.
Returns
-------
article : newspaper.Article
The article downloaded and parsed.
"""
# define the article
article = Article(url)
# download and parse the article
article.download()
article.parse()
# return the article
return article.text
# APP
# set title and subtitle
st.title("SummarizeLink")
st.markdown("Paste any article link below and click on the 'Summarize' button.")
st.markdown("*Note:* We truncate the text incase the article is lengthy! π")
# create the input text box and setting panel
link = st.text_area('Paste your link here...', "https://towardsdatascience.com/a-guide-to-the-knowledge-graphs-bfb5c40272f1", height=50)
button = st.button("Summarize")
min_length = st.sidebar.slider('Min summary length', min_value=10, max_value=100, value=50, step=10)
max_length = st.sidebar.slider('Max summary length', min_value=30, max_value=700, value=100, step=10)
num_beams = st.sidebar.slider('Beam length', min_value=1, max_value=10, value=5, step=1)
# if button is clicked
with st.spinner("Parsing article and Summarizing..."):
if button and link:
# get the text
text = download_and_parse_article(link)
# summarize the text
summary = summ(text,
truncation=True,
max_length = max_length,
min_length = min_length,
num_beams=num_beams,
do_sample=True,
early_stopping=True,
repetition_penalty=1.5,
length_penalty=1.5)[0]
# display the summary
st.markdown("**Summary:**")
st.write(summary['summary_text'])
|