pramudyalyza commited on
Commit
fdb7855
·
verified ·
1 Parent(s): dc96491

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +21 -14
  2. 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 pygooglenews import GoogleNews
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
- gn = GoogleNews(lang='id', country='ID')
15
- search = gn.search(keyword)
16
-
 
 
17
  filtered_headlines = []
18
- for entry in search['entries']:
19
- published_date = datetime.datetime.strptime(entry['published'], '%a, %d %b %Y %H:%M:%S %Z')
20
  if published_date > one_week_ago:
21
- filtered_headlines.append(entry['title'])
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
- positive_count, negative_count, total_count, df_clean = process_keyword(keyword_input)
 
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
- # Display results
69
- st.plotly_chart(fig_positive)
70
- st.plotly_chart(fig_negative)
71
- st.plotly_chart(fig_donut)
 
 
 
 
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
- setuptools==58
2
- pygooglenews==0.1.2
3
- feedparser==6.0.11
4
- pandas==2.2.3
5
- plotly==5.24.1
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