Upload 2 files
Browse files- app.py +21 -14
- requirements.txt +5 -7
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import datetime
|
3 |
import pandas as pd
|
4 |
-
from
|
5 |
from transformers import pipeline
|
6 |
import plotly.graph_objects as go
|
7 |
|
@@ -11,15 +11,17 @@ pipe = pipeline("text-classification", model="pramudyalyza/bert-indonesian-finet
|
|
11 |
# Function to process the keyword and get sentiment analysis
|
12 |
def process_keyword(keyword):
|
13 |
one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
17 |
filtered_headlines = []
|
18 |
-
for
|
19 |
-
published_date = datetime.datetime.strptime(
|
20 |
if published_date > one_week_ago:
|
21 |
-
filtered_headlines.append(
|
22 |
-
|
23 |
df = pd.DataFrame(filtered_headlines, columns=['title'])
|
24 |
df_clean = df.drop_duplicates()
|
25 |
|
@@ -38,7 +40,8 @@ keyword_input = st.text_input("Enter a keyword to search for news", placeholder=
|
|
38 |
|
39 |
if st.button("Analyze"):
|
40 |
if keyword_input:
|
41 |
-
|
|
|
42 |
|
43 |
# Create plots
|
44 |
fig_positive = go.Figure(go.Indicator(
|
@@ -65,14 +68,18 @@ if st.button("Analyze"):
|
|
65 |
))
|
66 |
fig_donut.update_layout(title_text='Sentiment Distribution')
|
67 |
|
68 |
-
#
|
69 |
-
st.
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
72 |
st.write(f"News articles found: {total_count}")
|
73 |
|
74 |
# Show DataFrame
|
75 |
-
st.dataframe(df_clean)
|
76 |
|
77 |
# Download CSV
|
78 |
csv = df_clean.to_csv(index=False).encode('utf-8')
|
|
|
1 |
import streamlit as st
|
2 |
import datetime
|
3 |
import pandas as pd
|
4 |
+
from gnews import GNews
|
5 |
from transformers import pipeline
|
6 |
import plotly.graph_objects as go
|
7 |
|
|
|
11 |
# Function to process the keyword and get sentiment analysis
|
12 |
def process_keyword(keyword):
|
13 |
one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
|
14 |
+
|
15 |
+
news = GNews(language='id', country='ID', max_results=100)
|
16 |
+
|
17 |
+
search_results = news.get_news(keyword)
|
18 |
+
|
19 |
filtered_headlines = []
|
20 |
+
for article in search_results:
|
21 |
+
published_date = datetime.datetime.strptime(article['published date'], '%a, %d %b %Y %H:%M:%S %Z')
|
22 |
if published_date > one_week_ago:
|
23 |
+
filtered_headlines.append(article['title'])
|
24 |
+
|
25 |
df = pd.DataFrame(filtered_headlines, columns=['title'])
|
26 |
df_clean = df.drop_duplicates()
|
27 |
|
|
|
40 |
|
41 |
if st.button("Analyze"):
|
42 |
if keyword_input:
|
43 |
+
with st.spinner('Scraping and analyzing the data...'):
|
44 |
+
positive_count, negative_count, total_count, df_clean = process_keyword(keyword_input)
|
45 |
|
46 |
# Create plots
|
47 |
fig_positive = go.Figure(go.Indicator(
|
|
|
68 |
))
|
69 |
fig_donut.update_layout(title_text='Sentiment Distribution')
|
70 |
|
71 |
+
# Create a horizontal layout using st.columns
|
72 |
+
col1, col2, col3 = st.columns(3)
|
73 |
+
|
74 |
+
# Display results in each column
|
75 |
+
col1.plotly_chart(fig_positive, use_container_width=True)
|
76 |
+
col2.plotly_chart(fig_negative, use_container_width=True)
|
77 |
+
col3.plotly_chart(fig_donut, use_container_width=True)
|
78 |
+
|
79 |
st.write(f"News articles found: {total_count}")
|
80 |
|
81 |
# Show DataFrame
|
82 |
+
st.dataframe(df_clean, use_container_width=True)
|
83 |
|
84 |
# Download CSV
|
85 |
csv = df_clean.to_csv(index=False).encode('utf-8')
|
requirements.txt
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
streamlit==1.37.1
|
7 |
-
transformers==4.36.2
|
|
|
1 |
+
gnews==0.3.7
|
2 |
+
pandas==2.2.3
|
3 |
+
plotly==5.24.1
|
4 |
+
streamlit==1.37.1
|
5 |
+
transformers==4.36.2
|
|
|
|