menikev commited on
Commit
836b08d
1 Parent(s): 21b510b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -2
app.py CHANGED
@@ -82,6 +82,49 @@ def create_sentiment_discrimination_grouped_chart(df):
82
  fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Sentiment", yaxis_title="Count", font=dict(size=12))
83
  return fig
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  # Function for Channel-wise Sentiment Over Time Chart
86
  def create_channel_sentiment_over_time_chart(df):
87
  df['Date'] = pd.to_datetime(df['Date'])
@@ -116,11 +159,25 @@ def render_dashboard(page, df_filtered):
116
 
117
  elif page == "Sentiment Analysis":
118
  st.title("Sentiment Analysis Dashboard")
119
- # Implement sentiment analysis visualizations here
 
 
 
 
 
120
 
 
 
 
 
121
  elif page == "Discrimination Analysis":
122
  st.title("Discrimination Analysis Dashboard")
123
- # Implement discrimination analysis visualizations here
 
 
 
 
 
124
 
125
  elif page == "Channel Analysis":
126
  st.title("Channel Analysis Dashboard")
 
82
  fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Sentiment", yaxis_title="Count", font=dict(size=12))
83
  return fig
84
 
85
+ # Function for Top Domains with Negative Sentiment Chart
86
+ def create_top_negative_sentiment_domains_chart(df):
87
+ domain_counts = df.groupby(['Domain', 'Sentiment']).size().unstack(fill_value=0)
88
+ domain_counts.sort_values(by='Negative', ascending=False, inplace=True)
89
+ domain_counts_subset = domain_counts.iloc[:3, [0]]
90
+ domain_counts_subset = domain_counts_subset.rename(columns={domain_counts_subset.columns[0]: 'Count'})
91
+ domain_counts_subset = domain_counts_subset.reset_index()
92
+ colors = ['limegreen', 'crimson', 'darkcyan']
93
+ fig = px.bar(domain_counts_subset, x='Count', y='Domain', title='Top Domains with Negative Sentiment', color='Domain',
94
+ orientation='h', color_discrete_sequence=colors)
95
+ fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Negative sentiment content Count", yaxis_title="Domain")
96
+ return fig
97
+
98
+ # Function for Key Phrases in Negative Sentiment Content Chart
99
+ def create_key_phrases_negative_sentiment_chart(df):
100
+ cv = CountVectorizer(ngram_range=(3,3), stop_words='english')
101
+ trigrams = cv.fit_transform(df['Content'][df['Sentiment'] == 'Negative'])
102
+ count_values = trigrams.toarray().sum(axis=0)
103
+ ngram_freq = pd.DataFrame(sorted([(count_values[i], k) for k, i in cv.vocabulary_.items()], reverse=True))
104
+ ngram_freq.columns = ['frequency', 'ngram']
105
+ fig = px.bar(ngram_freq.head(10), x='frequency', y='ngram', orientation='h', title='Key phrases in Negative Sentiment Content')
106
+ fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Frequency", yaxis_title="Trigram")
107
+ return fig
108
+
109
+ # Function for Prevalence of Discriminatory Content Chart
110
+ def create_prevalence_discriminatory_content_chart(df):
111
+ domain_counts = df.groupby(['Domain', 'Discrimination']).size().unstack(fill_value=0)
112
+ fig = px.bar(domain_counts, x=domain_counts.index, y=['Discriminative', 'Non-Discriminative'], barmode='group',
113
+ title='Prevalence of Discriminatory Content')
114
+ fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Domain", yaxis_title="Count")
115
+ return fig
116
+
117
+ # Function for Top Domains with Discriminatory Content Chart
118
+ def create_top_discriminatory_domains_chart(df):
119
+ domain_counts = df.groupby(['Domain', 'Discrimination']).size().unstack(fill_value=0)
120
+ domain_counts.sort_values(by='Discriminative', ascending=False, inplace=True)
121
+ domain_counts_subset = domain_counts.iloc[:3]
122
+ domain_counts_subset = domain_counts_subset.rename(columns={'Discriminative': 'Count'})
123
+ fig = px.bar(domain_counts_subset, x='Count', y=domain_counts_subset.index, orientation='h',
124
+ title='Top Domains with Discriminatory Content')
125
+ fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Discriminatory Content Count", yaxis_title="Domain")
126
+ return fig
127
+
128
  # Function for Channel-wise Sentiment Over Time Chart
129
  def create_channel_sentiment_over_time_chart(df):
130
  df['Date'] = pd.to_datetime(df['Date'])
 
159
 
160
  elif page == "Sentiment Analysis":
161
  st.title("Sentiment Analysis Dashboard")
162
+ # Create visualizations for the sentiment analysis page
163
+ col1, col2 = st.beta_columns(2)
164
+ with col1:
165
+ st.plotly_chart(create_sentiment_distribution_chart(df_filtered))
166
+ with col2:
167
+ st.plotly_chart(create_top_negative_sentiment_domains_chart(df_filtered))
168
 
169
+ col3, col4 = st.beta_columns(2)
170
+ with col3:
171
+ st.plotly_chart(create_key_phrases_negative_sentiment_chart(df_filtered))
172
+
173
  elif page == "Discrimination Analysis":
174
  st.title("Discrimination Analysis Dashboard")
175
+ # Create visualizations for the discrimination analysis page
176
+ col1, col2 = st.beta_columns(2)
177
+ with col1:
178
+ st.plotly_chart(create_prevalence_discriminatory_content_chart(df_filtered))
179
+ with col2:
180
+ st.plotly_chart(create_top_discriminatory_domains_chart(df_filtered))e
181
 
182
  elif page == "Channel Analysis":
183
  st.title("Channel Analysis Dashboard")