yassTrad commited on
Commit
3dabb3d
1 Parent(s): a07bae2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from summarizer import Summarizer
2
+ #from goose3 import Goose
3
+ from newsplease import NewsPlease
4
+ import validators
5
+ import streamlit as st
6
+ import warnings
7
+ warnings.filterwarnings("ignore")
8
+
9
+ def article_text_extractor(url: str):
10
+ '''Extract text from url'''
11
+ article = NewsPlease.from_url(entry.link)
12
+
13
+ return article.maintext
14
+
15
+
16
+ @st.cache(allow_output_mutation=True)
17
+ def model():
18
+ model = Summarizer()
19
+ return model
20
+
21
+ #Streamlit App
22
+
23
+ st.title("Article Extractive Summarizer")
24
+
25
+ st.markdown(
26
+ "This application aims to make an extractive summary of newspaper articles from the text of the article or the url link of the article. The summary is based on a BERT model.""")
27
+
28
+ st.markdown("""Please do note that the model will take longer to generate summaries for documents that are too long.""")
29
+
30
+ st.markdown(
31
+ "As input we only ingests the below formats :"
32
+ )
33
+
34
+ st.markdown(
35
+ """- Raw text entered in text box.
36
+ - URL of an article to be summarized."""
37
+ )
38
+
39
+ st.markdown("---")
40
+
41
+ url_text = st.text_input("Please Enter a url here")
42
+
43
+ st.markdown(
44
+ "<h3 style='text-align: center; color: red;'>OR</h3>",
45
+ unsafe_allow_html=True,
46
+ )
47
+
48
+ plain_text = st.text_input("Please Paste/Enter plain text here")
49
+
50
+ is_url = validators.url(url_text)
51
+
52
+ if is_url:
53
+ # complete text
54
+ clean_text = article_text_extractor(url=url_text)
55
+
56
+ summarize = st.button("Summarize")
57
+
58
+ if summarize:
59
+ text_to_summarize = clean_text if is_url else plain_text
60
+
61
+ with st.spinner(text="Loading Model and Extracting summary. This might take a few seconds depending on the length of your text..."):
62
+ model = model()
63
+ summarized_text = text_to_summarize if len(text_to_summarize) > 60 else ''.join(model(body, min_length=60))
64
+
65
+ st.subheader("Summarized text")
66
+
67
+ st.write(summarized_text)