Bayhaqy commited on
Commit
ce083b1
1 Parent(s): 9fa7b4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -38
app.py CHANGED
@@ -3,7 +3,8 @@ import json
3
  import requests
4
  import time
5
  from newspaper import Article
6
-
 
7
 
8
  # Page title layout
9
  c1, c2 = st.columns([0.32, 2])
@@ -13,13 +14,13 @@ with c1:
13
 
14
  with c2:
15
  st.title("Website Article Summarize")
16
- st.markdown("**Generate summaries of articles from websites using abstractive summarization with Google's Pegasus language model.**")
17
  st.caption("Created by Bayhaqy.")
18
 
19
  # Sidebar content
20
  st.sidebar.subheader("About the app")
21
  st.sidebar.info("This app uses optional 🤗HuggingFace's Model [facebook/bart-large-cnn](https://huggingface.co/facebook/bart-large-cnn) \
22
- or [pegasus_indonesian_base-finetune](https://huggingface.co/pegasus_indonesian_base-finetune) model.")
23
  st.sidebar.write("\n\n")
24
  st.sidebar.markdown("**Get a free API key from HuggingFace:**")
25
  st.sidebar.markdown("* Create a [free account](https://huggingface.co/join) or [login](https://huggingface.co/login)")
@@ -27,7 +28,7 @@ st.sidebar.markdown("* Go to **Settings** and then **Access Tokens**")
27
  st.sidebar.markdown("* Create a new Token (select 'read' role)")
28
  st.sidebar.markdown("* Paste your API key in the text box")
29
  st.sidebar.divider()
30
- st.sidebar.write("Please make sure your article is in English/Indonesia, choose the correct model and is not behind a paywall.")
31
  st.sidebar.write("\n\n")
32
  st.sidebar.divider()
33
 
@@ -55,28 +56,18 @@ if fetch_button:
55
  time.sleep(3)
56
  st.success('Your article is ready for summarization!')
57
 
58
- view_button = st.button("View Article")
 
 
 
 
 
59
 
60
- if view_button:
61
- article = Article(url)
62
- article.download()
63
- article.parse()
64
-
65
- title = article.title
66
- text = article.text
67
- html = article.html
68
-
69
- st.divider()
70
- st.subheader("Real Article")
71
- st.markdown(f"Your article: **{title}**")
72
- st.markdown(f"**{text}**")
73
- st.divider()
74
-
75
- st.divider()
76
- st.subheader("Real Article (HTML)")
77
- st.code(f"Your article: **{title}**",language='html')
78
- st.code(f"**{html}**",language='html')
79
- st.divider()
80
 
81
  else:
82
  st.write("Error occurred while fetching article.")
@@ -99,9 +90,6 @@ if selected_api_url == "bart-large-cnn":
99
  else:
100
  API_URL = "https://api-inference.huggingface.co/models/thonyyy/pegasus_indonesian_base-finetune"
101
 
102
-
103
- API_URL_TL = "https://api-inference.huggingface.co/models/facebook/mbart-large-50-many-to-many-mmt"
104
-
105
  submit_button = st.button("Submit to Summarize")
106
 
107
  # Download and parse the article
@@ -109,10 +97,12 @@ if submit_button:
109
  article = Article(url)
110
  article.download()
111
  article.parse()
 
112
 
113
  title = article.title
114
  text = article.text
115
  html = article.html
 
116
 
117
  # HuggingFace API request function summary
118
  def query_sum(payload):
@@ -134,19 +124,11 @@ if submit_button:
134
  st.markdown(f"**{summary}**")
135
 
136
  st.divider()
137
- st.subheader("Real Article")
138
  st.markdown(f"Your article: **{title}**")
139
- st.markdown(f"**{text}**")
140
- st.divider()
141
 
142
  st.divider()
143
  st.subheader("Real Article")
144
  st.markdown(f"Your article: **{title}**")
145
  st.markdown(f"**{text}**")
146
- st.divider()
147
-
148
- st.divider()
149
- st.subheader("Real Article (HTML)")
150
- st.code(f"Your article: **{title}**",language='html')
151
- st.code(f"**{html}**",language='html')
152
- st.divider()
 
3
  import requests
4
  import time
5
  from newspaper import Article
6
+ import nltk
7
+ nltk.download('punkt')
8
 
9
  # Page title layout
10
  c1, c2 = st.columns([0.32, 2])
 
14
 
15
  with c2:
16
  st.title("Website Article Summarize")
17
+ st.markdown("**Generate summaries of articles from websites using abstractive summarization with Language Model and Library NewsPaper.**")
18
  st.caption("Created by Bayhaqy.")
19
 
20
  # Sidebar content
21
  st.sidebar.subheader("About the app")
22
  st.sidebar.info("This app uses optional 🤗HuggingFace's Model [facebook/bart-large-cnn](https://huggingface.co/facebook/bart-large-cnn) \
23
+ or [pegasus_indonesian_base-finetune](https://huggingface.co/pegasus_indonesian_base-finetune) model and Library NewsPaper.")
24
  st.sidebar.write("\n\n")
25
  st.sidebar.markdown("**Get a free API key from HuggingFace:**")
26
  st.sidebar.markdown("* Create a [free account](https://huggingface.co/join) or [login](https://huggingface.co/login)")
 
28
  st.sidebar.markdown("* Create a new Token (select 'read' role)")
29
  st.sidebar.markdown("* Paste your API key in the text box")
30
  st.sidebar.divider()
31
+ st.sidebar.write("Please make sure you choose the correct model and is not behind a paywall.")
32
  st.sidebar.write("\n\n")
33
  st.sidebar.divider()
34
 
 
56
  time.sleep(3)
57
  st.success('Your article is ready for summarization!')
58
 
59
+ article = Article(url)
60
+ article.download()
61
+ article.parse()
62
+
63
+ title = article.title
64
+ text = article.text
65
 
66
+ st.divider()
67
+ st.subheader("Real Article")
68
+ st.markdown(f"Your article: **{title}**")
69
+ st.markdown(f"**{text}**")
70
+ st.divider()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  else:
73
  st.write("Error occurred while fetching article.")
 
90
  else:
91
  API_URL = "https://api-inference.huggingface.co/models/thonyyy/pegasus_indonesian_base-finetune"
92
 
 
 
 
93
  submit_button = st.button("Submit to Summarize")
94
 
95
  # Download and parse the article
 
97
  article = Article(url)
98
  article.download()
99
  article.parse()
100
+ article.nlp()
101
 
102
  title = article.title
103
  text = article.text
104
  html = article.html
105
+ summ = article.summary
106
 
107
  # HuggingFace API request function summary
108
  def query_sum(payload):
 
124
  st.markdown(f"**{summary}**")
125
 
126
  st.divider()
127
+ st.subheader("Summary Library NewsPaper")
128
  st.markdown(f"Your article: **{title}**")
129
+ st.markdown(f"**{summ}**")
 
130
 
131
  st.divider()
132
  st.subheader("Real Article")
133
  st.markdown(f"Your article: **{title}**")
134
  st.markdown(f"**{text}**")