Bayhaqy commited on
Commit
c4992a5
1 Parent(s): 4910f63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -131
app.py CHANGED
@@ -1,134 +1,10 @@
1
  import streamlit as st
2
- import json
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])
11
 
12
- with c1:
13
- st.image("images/newspaper.png", width=85)
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)")
27
- st.sidebar.markdown("* Go to **Settings** and then **Access Tokens**")
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
-
35
- # Inputs
36
- st.subheader("Enter the URL of the article you want to summarize")
37
- default_url = "https://"
38
- url = st.text_input("URL:", default_url)
39
-
40
- headers_ = {
41
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36'
42
- }
43
-
44
- fetch_button = st.button("Fetch article")
45
-
46
- if fetch_button:
47
- article_url = url
48
- session = requests.Session()
49
-
50
- try:
51
- response_ = session.get(article_url, headers=headers_, timeout=10)
52
-
53
- if response_.status_code == 200:
54
-
55
- with st.spinner('Fetching your article...'):
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.")
74
-
75
- except Exception as e:
76
- st.write(f"Error occurred while fetching article: {e}")
77
-
78
- # HuggingFace API KEY input
79
- API_KEY = st.text_input("Enter your HuggingFace API key", type="password")
80
-
81
- headers = {"Authorization": f"Bearer {API_KEY}"}
82
-
83
-
84
- # Selectbox to choose between API URLs
85
- selected_api_url = st.selectbox("Select Model", options=["bart-large-cnn", "pegasus_indonesian_base-finetune"])
86
-
87
- # Determine the selected Model
88
- if selected_api_url == "bart-large-cnn":
89
- API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
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
96
- if submit_button:
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):
109
- response = requests.post(API_URL, headers=headers, json=payload)
110
- return response.json()
111
-
112
- with st.spinner('Doing some AI magic, please wait...'):
113
- time.sleep(1)
114
-
115
- # Query the API Summary
116
- output_sum = query_sum({"inputs": text, })
117
-
118
- # Display the results
119
- summary = output_sum[0]['summary_text'].replace('<n>', " ")
120
-
121
- st.divider()
122
- st.subheader("Summary AI")
123
- st.markdown(f"Your article: **{title}**")
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}**")
 
1
  import streamlit as st
 
 
 
 
 
 
2
 
 
 
3
 
4
+ st.set_page_config(page_title='Classification - News Analysis and Prediction', layout='wide', page_icon='📃')
5
+ st.title("📃 Classification - News Analysis and Prediction")
6
+ st.write(
7
+ """
8
+ Welcome to the **📃 Classification - News Analysis and Prediction App**!
9
+ """
10
+ )