yassTrad commited on
Commit
f9fc694
1 Parent(s): be2791c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -19,36 +19,33 @@ def article_text_extractor(url: str):
19
  text = text if "REUTERS" not in first_sentence else "\n".join(list(filter(None, text.split("\n")))[1:])
20
  return text
21
 
22
- def article_text_extractor_(url: str):
23
- '''Extract text from url'''
24
- ua = UserAgent()
25
- headers = {'User-Agent':str(ua.chrome)}
26
-
27
- r = requests.get(url,headers=headers)
28
-
29
- soup = BeautifulSoup(r.text, "html.parser")
30
- title_text = soup.find_all(["h1"])
31
- para_text = soup.find_all(["p"])
32
- article_text = [result.text for result in para_text]
33
- article_header = [result.text for result in title_text][0]
34
- article = " ".join(article_text)
35
- article = article.replace(".", ".<eos>")
36
- article = article.replace("!", "!<eos>")
37
- article = article.replace("?", "?<eos>")
38
- sentences = article.split("<eos>")
39
-
40
- return ' '.join(sentences)
41
 
42
 
43
  @st.cache(allow_output_mutation=True)
44
- def model():
45
  model = Summarizer()
46
  return model
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  #Streamlit App
49
 
50
  st.title("Article Extractive Summarizer")
51
 
 
 
52
  st.markdown(
53
  "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.""")
54
 
 
19
  text = text if "REUTERS" not in first_sentence else "\n".join(list(filter(None, text.split("\n")))[1:])
20
  return text
21
 
22
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
 
25
  @st.cache(allow_output_mutation=True)
26
+ def extractive_model():
27
  model = Summarizer()
28
  return model
29
 
30
+ @st.cache(allow_output_mutation=True)
31
+ def facebook_model():
32
+ summarizer = pipeline('summarization',model='facebook/bart-large-cnn')
33
+ return summarizer
34
+
35
+ @st.cache(allow_output_mutation=True)
36
+ def model():
37
+ if summary_type == "Abstractive":
38
+ return facebook_model()
39
+ else:
40
+ return extractive_model()
41
+
42
+
43
  #Streamlit App
44
 
45
  st.title("Article Extractive Summarizer")
46
 
47
+ summary_type = st.sidebar.selectbox("Summary type", options=["Abstractive", "Extractive"])
48
+
49
  st.markdown(
50
  "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.""")
51