File size: 1,857 Bytes
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
# 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'])