mohitmayank commited on
Commit
81b2b07
1 Parent(s): 5e31f58

initial version

Browse files
Files changed (2) hide show
  1. app.py +44 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import
2
+ from tensorflow.python.keras.utils.generic_utils import default
3
+ import streamlit as st
4
+ from newspaper import Article
5
+ from transformers import pipeline
6
+
7
+ st.set_page_config(layout="wide", page_title="SummarizeLink")
8
+
9
+ # load the summarization model
10
+ @st.cache(allow_output_mutation=True)
11
+ def load_summarize_model():
12
+ # model = pipeline("summarization", model='sshleifer/distilbart-cnn-12-6')
13
+ model = pipeline("summarization")
14
+ return model
15
+ summ = load_summarize_model()
16
+
17
+ # define functions
18
+ def download_and_parse_article(url):
19
+ article = Article(url)
20
+ article.download()
21
+ article.parse()
22
+ return article.text
23
+
24
+ # define the app
25
+ st.title("SummarizeLink")
26
+ st.text("Paste any article link below and click on the 'Summarize Text' button to get the summarized data")
27
+ # st.subheader("This application is using HuggingFace's transformers pre-trained model for text summarization.")
28
+ link = st.text_area('Paste your link here...', "https://towardsdatascience.com/a-guide-to-the-knowledge-graphs-bfb5c40272f1", height=50)
29
+ button = st.button("Summarize")
30
+ max_lengthy = st.sidebar.slider('Max summary length', min_value=30, max_value=700, value=100, step=10)
31
+ # 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)
32
+ with st.spinner("Summarizing..."):
33
+ if button and link:
34
+ text = download_and_parse_article(link) # get the text
35
+ summary = summ(text,
36
+ truncation=True,
37
+ max_length = max_lengthy,
38
+ min_length = 50,
39
+ num_beams=5,
40
+ do_sample=True,
41
+ early_stopping=True,
42
+ repetition_penalty=1.5,
43
+ length_penalty=1.5)[0]
44
+ st.write(summary['summary_text'])
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ newspaper