pramudyalyza commited on
Commit
7555431
·
verified ·
1 Parent(s): 323cd15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -6,7 +6,7 @@ from transformers import pipeline
6
  import plotly.graph_objects as go
7
 
8
  # Load the sentiment analysis model
9
- pipe = pipeline("text-classification", model="pramudyalyza/bert-indonesian-finetuned-news")
10
 
11
  # Function to process the keyword and get sentiment analysis
12
  def process_keyword(keyword):
@@ -29,9 +29,10 @@ def process_keyword(keyword):
29
 
30
  positive_count = (df_clean['sentiment'] == 'Positive').sum()
31
  negative_count = (df_clean['sentiment'] == 'Negative').sum()
 
32
  total_count = len(df_clean)
33
 
34
- return positive_count, negative_count, total_count, df_clean
35
 
36
  # Streamlit app layout
37
  st.title("News Sentiment Analysis Dashboard")
@@ -41,7 +42,7 @@ keyword_input = st.text_input("Enter a keyword to search for news", placeholder=
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(
@@ -60,11 +61,19 @@ if st.button("Analyze"):
60
  'bar': {'color': "red"}}
61
  ))
62
 
 
 
 
 
 
 
 
 
63
  fig_donut = go.Figure(go.Pie(
64
- labels=['Positive', 'Negative'],
65
- values=[positive_count, negative_count],
66
  hole=0.5,
67
- marker=dict(colors=['green', 'red'])
68
  ))
69
  fig_donut.update_layout(title_text='Sentiment Distribution')
70
 
@@ -74,7 +83,9 @@ if st.button("Analyze"):
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
 
 
6
  import plotly.graph_objects as go
7
 
8
  # Load the sentiment analysis model
9
+ pipe = pipeline("text-classification", model="pramudyalyza/bert-indonesian-finetuned-news-v2")
10
 
11
  # Function to process the keyword and get sentiment analysis
12
  def process_keyword(keyword):
 
29
 
30
  positive_count = (df_clean['sentiment'] == 'Positive').sum()
31
  negative_count = (df_clean['sentiment'] == 'Negative').sum()
32
+ neutral_count = (df_clean['sentiment'] == 'Neutral').sum()
33
  total_count = len(df_clean)
34
 
35
+ return positive_count, negative_count, neutral_count, total_count, df_clean
36
 
37
  # Streamlit app layout
38
  st.title("News Sentiment Analysis Dashboard")
 
42
  if st.button("Analyze"):
43
  if keyword_input:
44
  with st.spinner('Scraping and analyzing the data...'):
45
+ positive_count, negative_count, neutral_count, total_count, df_clean = process_keyword(keyword_input)
46
 
47
  # Create plots
48
  fig_positive = go.Figure(go.Indicator(
 
61
  'bar': {'color': "red"}}
62
  ))
63
 
64
+ fig_neutral = go.Figure(go.Indicator(
65
+ mode="gauge+number",
66
+ value=neutral_count,
67
+ title={'text': "Neutral Sentiment"},
68
+ gauge={'axis': {'range': [0, total_count]},
69
+ 'bar': {'color': "yellow"}}
70
+ ))
71
+
72
  fig_donut = go.Figure(go.Pie(
73
+ labels=['Positive', 'Negative', 'Neutral'],
74
+ values=[positive_count, negative_count, neutral_count],
75
  hole=0.5,
76
+ marker=dict(colors=['green', 'red', 'yellow'])
77
  ))
78
  fig_donut.update_layout(title_text='Sentiment Distribution')
79
 
 
83
  # Display results in each column
84
  col1.plotly_chart(fig_positive, use_container_width=True)
85
  col2.plotly_chart(fig_negative, use_container_width=True)
86
+ col3.plotly_chart(fig_neutral, use_container_width=True)
87
+
88
+ st.plotly_chart(fig_donut, use_container_width=True)
89
 
90
  st.write(f"News articles found: {total_count}")
91