menikev commited on
Commit
d4b293d
1 Parent(s): 5256c84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -63,7 +63,7 @@ color_palette = px.colors.sequential.Viridis
63
  # Visualisation for Domain Distribution
64
  def create_pie_chart(df, column, title):
65
  fig = px.pie(df, names=column, title=title, hole=0.35)
66
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), legend=dict(x=0.1, y=1), font=dict(size=7))
67
  fig.update_traces(marker=dict(colors=color_palette))
68
  return fig
69
 
@@ -71,7 +71,7 @@ def create_pie_chart(df, column, title):
71
  def create_gender_ethnicity_distribution_chart(df):
72
  df['GenderOrEthnicity'] = df['Domain'].apply(lambda x: "Gender: Women & LGBTQIA+" if x in ["Women", "LGBTQIA+"] else "Ethnicity")
73
  fig = px.pie(df, names='GenderOrEthnicity', title='Distribution of Gender versus Ethnicity', hole=0.35)
74
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), legend=dict(x=0.1, y=1), font=dict(size=7))
75
  return fig
76
 
77
  # Visualization for Sentiment Distribution Across Domains
@@ -79,7 +79,7 @@ def create_sentiment_distribution_chart(df):
79
  df['Discrimination'] = df['Discrimination'].replace({"Non Discriminative": "Non-Discriminative"}) # Assuming typo in the original script
80
  domain_counts = df.groupby(['Domain', 'Sentiment']).size().reset_index(name='counts')
81
  fig = px.bar(domain_counts, x='Domain', y='counts', color='Sentiment', title="Sentiment Distribution Across Domains", barmode='stack')
82
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Domain", yaxis_title="Counts", font=dict(size=7))
83
  return fig
84
 
85
  # Visualization for Correlation between Sentiment and Discrimination
@@ -88,7 +88,7 @@ def create_sentiment_discrimination_grouped_chart(df):
88
  crosstab_df = pd.crosstab(df['Sentiment'], df['Discrimination'])
89
 
90
  # Check if 'Yes' and 'No' are in the columns after the crosstab operation
91
- value_vars = crosstab_df.columns.intersection(['Yes', 'No']).tolist()
92
 
93
  # If 'No' is not in columns, it will not be included in melting
94
  melted_df = pd.melt(crosstab_df.reset_index(), id_vars='Sentiment', value_vars=value_vars, var_name='Discrimination', value_name='Count')
@@ -96,7 +96,7 @@ def create_sentiment_discrimination_grouped_chart(df):
96
  # Proceeding to plot only if we have data to plot
97
  if not melted_df.empty:
98
  fig = px.bar(melted_df, x='Sentiment', y='Count', color='Discrimination', barmode='group', title="Sentiment vs. Discrimination")
99
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Sentiment", yaxis_title="Count", font=dict(size=7))
100
  return fig
101
  else:
102
  return "No data to display for the selected filters."
@@ -111,7 +111,7 @@ def create_top_negative_sentiment_domains_chart(df):
111
  colors = ['limegreen', 'crimson', 'darkcyan']
112
  fig = px.bar(domain_counts_subset, x='Count', y='Domain', title='Top Domains with Negative Sentiment', color='Domain',
113
  orientation='h', color_discrete_sequence=colors)
114
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Negative sentiment content Count", yaxis_title="Domain", font=dict(size=7))
115
  return fig
116
 
117
  # Function for Key Phrases in Negative Sentiment Content Chart
@@ -122,7 +122,7 @@ def create_key_phrases_negative_sentiment_chart(df):
122
  ngram_freq = pd.DataFrame(sorted([(count_values[i], k) for k, i in cv.vocabulary_.items()], reverse=True))
123
  ngram_freq.columns = ['frequency', 'ngram']
124
  fig = px.bar(ngram_freq.head(10), x='frequency', y='ngram', orientation='h', title='Key phrases in Negative Sentiment Content')
125
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Frequency", yaxis_title="Trigram", font=dict(size=7))
126
  return fig
127
 
128
  # Function for Key Phrases in Positive Sentiment Content Chart
@@ -133,7 +133,7 @@ def create_key_phrases_positive_sentiment_chart(df):
133
  ngram_freq = pd.DataFrame(sorted([(count_values[i], k) for k, i in cv.vocabulary_.items()], reverse=True))
134
  ngram_freq.columns = ['frequency', 'ngram']
135
  fig = px.bar(ngram_freq.head(10), x='frequency', y='ngram', orientation='h', title='Key phrases in Positive Sentiment Content')
136
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Frequency", yaxis_title="Trigram", font=dict(size=7))
137
  return fig
138
 
139
  # Function for Prevalence of Discriminatory Content Chart
@@ -141,7 +141,7 @@ def create_prevalence_discriminatory_content_chart(df):
141
  domain_counts = df.groupby(['Domain', 'Discrimination']).size().unstack(fill_value=0)
142
  fig = px.bar(domain_counts, x=domain_counts.index, y=['Discriminative', 'Non-Discriminative'], barmode='group',
143
  title='Prevalence of Discriminatory Content')
144
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Domain", yaxis_title="Count", font=dict(size=7))
145
  return fig
146
 
147
  # Function for Top Domains with Discriminatory Content Chart
@@ -152,21 +152,21 @@ def create_top_discriminatory_domains_chart(df):
152
  domain_counts_subset = domain_counts_subset.rename(columns={'Discriminative': 'Count'})
153
  fig = px.bar(domain_counts_subset, x='Count', y=domain_counts_subset.index, orientation='h',
154
  title='Top Domains with Discriminatory Content')
155
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Discriminatory Content Count", yaxis_title="Domain", font=dict(size=7))
156
  return fig
157
 
158
  # Function for Channel-wise Sentiment Over Time Chart
159
  def create_sentiment_distribution_by_channel_chart(df):
160
  sentiment_by_channel = df.groupby(['Channel', 'Sentiment']).size().reset_index(name='counts')
161
  fig = px.bar(sentiment_by_channel, x='Channel', y='counts', color='Sentiment', title="Sentiment Distribution by Channel", barmode='group')
162
- fig.update_layout(margin=dict(l=6, r=6, t=12, b=6), xaxis_title="Channel", yaxis_title="Counts", font=dict(size=7))
163
  return fig
164
 
165
  # Function for Channel-wise Distribution of Discriminative Content Chart
166
  def create_channel_discrimination_chart(df):
167
  channel_discrimination = df.groupby(['Channel', 'Discrimination']).size().unstack(fill_value=0)
168
  fig = px.bar(channel_discrimination, x=channel_discrimination.index, y=['Discriminative', 'Non-Discriminative'], barmode='group')
169
- fig.update_layout(title='Channel-wise Distribution of Discriminative Content', margin=dict(l=6, r=6, t=12, b=6), font=dict(size=7))
170
  return fig
171
 
172
  # Function for rendering dashboard
@@ -221,4 +221,4 @@ def render_dashboard(page, df_filtered):
221
 
222
 
223
  # Render the selected dashboard page
224
- render_dashboard(page, df_filtered)
 
63
  # Visualisation for Domain Distribution
64
  def create_pie_chart(df, column, title):
65
  fig = px.pie(df, names=column, title=title, hole=0.35)
66
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), legend=dict(x=0.1, y=1), font=dict(size=10), title_x=0.5)
67
  fig.update_traces(marker=dict(colors=color_palette))
68
  return fig
69
 
 
71
  def create_gender_ethnicity_distribution_chart(df):
72
  df['GenderOrEthnicity'] = df['Domain'].apply(lambda x: "Gender: Women & LGBTQIA+" if x in ["Women", "LGBTQIA+"] else "Ethnicity")
73
  fig = px.pie(df, names='GenderOrEthnicity', title='Distribution of Gender versus Ethnicity', hole=0.35)
74
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), legend=dict(x=0.1, y=1), font=dict(size=10), title_x=0.5)
75
  return fig
76
 
77
  # Visualization for Sentiment Distribution Across Domains
 
79
  df['Discrimination'] = df['Discrimination'].replace({"Non Discriminative": "Non-Discriminative"}) # Assuming typo in the original script
80
  domain_counts = df.groupby(['Domain', 'Sentiment']).size().reset_index(name='counts')
81
  fig = px.bar(domain_counts, x='Domain', y='counts', color='Sentiment', title="Sentiment Distribution Across Domains", barmode='stack')
82
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Domain", yaxis_title="Counts", font=dict(size=10), title_x=0.5)
83
  return fig
84
 
85
  # Visualization for Correlation between Sentiment and Discrimination
 
88
  crosstab_df = pd.crosstab(df['Sentiment'], df['Discrimination'])
89
 
90
  # Check if 'Yes' and 'No' are in the columns after the crosstab operation
91
+ value_vars = crosstab_df.columns.intersection(['Discriminative', 'Non Discriminative']).tolist()
92
 
93
  # If 'No' is not in columns, it will not be included in melting
94
  melted_df = pd.melt(crosstab_df.reset_index(), id_vars='Sentiment', value_vars=value_vars, var_name='Discrimination', value_name='Count')
 
96
  # Proceeding to plot only if we have data to plot
97
  if not melted_df.empty:
98
  fig = px.bar(melted_df, x='Sentiment', y='Count', color='Discrimination', barmode='group', title="Sentiment vs. Discrimination")
99
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Sentiment", yaxis_title="Count", font=dict(size=10), title_x=0.5)
100
  return fig
101
  else:
102
  return "No data to display for the selected filters."
 
111
  colors = ['limegreen', 'crimson', 'darkcyan']
112
  fig = px.bar(domain_counts_subset, x='Count', y='Domain', title='Top Domains with Negative Sentiment', color='Domain',
113
  orientation='h', color_discrete_sequence=colors)
114
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Negative sentiment content Count", yaxis_title="Domain", font=dict(size=10), title_x=0.5)
115
  return fig
116
 
117
  # Function for Key Phrases in Negative Sentiment Content Chart
 
122
  ngram_freq = pd.DataFrame(sorted([(count_values[i], k) for k, i in cv.vocabulary_.items()], reverse=True))
123
  ngram_freq.columns = ['frequency', 'ngram']
124
  fig = px.bar(ngram_freq.head(10), x='frequency', y='ngram', orientation='h', title='Key phrases in Negative Sentiment Content')
125
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Frequency", yaxis_title="Trigram", font=dict(size=10), title_x=0.5)
126
  return fig
127
 
128
  # Function for Key Phrases in Positive Sentiment Content Chart
 
133
  ngram_freq = pd.DataFrame(sorted([(count_values[i], k) for k, i in cv.vocabulary_.items()], reverse=True))
134
  ngram_freq.columns = ['frequency', 'ngram']
135
  fig = px.bar(ngram_freq.head(10), x='frequency', y='ngram', orientation='h', title='Key phrases in Positive Sentiment Content')
136
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Frequency", yaxis_title="Trigram", font=dict(size=10), title_x=0.5)
137
  return fig
138
 
139
  # Function for Prevalence of Discriminatory Content Chart
 
141
  domain_counts = df.groupby(['Domain', 'Discrimination']).size().unstack(fill_value=0)
142
  fig = px.bar(domain_counts, x=domain_counts.index, y=['Discriminative', 'Non-Discriminative'], barmode='group',
143
  title='Prevalence of Discriminatory Content')
144
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Domain", yaxis_title="Count", font=dict(size=10), title_x=0.5)
145
  return fig
146
 
147
  # Function for Top Domains with Discriminatory Content Chart
 
152
  domain_counts_subset = domain_counts_subset.rename(columns={'Discriminative': 'Count'})
153
  fig = px.bar(domain_counts_subset, x='Count', y=domain_counts_subset.index, orientation='h',
154
  title='Top Domains with Discriminatory Content')
155
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Discriminatory Content Count", yaxis_title="Domain", font=dict(size=10), title_x=0.5)
156
  return fig
157
 
158
  # Function for Channel-wise Sentiment Over Time Chart
159
  def create_sentiment_distribution_by_channel_chart(df):
160
  sentiment_by_channel = df.groupby(['Channel', 'Sentiment']).size().reset_index(name='counts')
161
  fig = px.bar(sentiment_by_channel, x='Channel', y='counts', color='Sentiment', title="Sentiment Distribution by Channel", barmode='group')
162
+ fig.update_layout(margin=dict(l=20, r=20, t=50, b=20), xaxis_title="Channel", yaxis_title="Counts", font=dict(size=10), title_x=0.5)
163
  return fig
164
 
165
  # Function for Channel-wise Distribution of Discriminative Content Chart
166
  def create_channel_discrimination_chart(df):
167
  channel_discrimination = df.groupby(['Channel', 'Discrimination']).size().unstack(fill_value=0)
168
  fig = px.bar(channel_discrimination, x=channel_discrimination.index, y=['Discriminative', 'Non-Discriminative'], barmode='group')
169
+ fig.update_layout(title='Channel-wise Distribution of Discriminative Content', margin=dict(l=20, r=20, t=50, b=20), font=dict(size=10), title_x=0.5)
170
  return fig
171
 
172
  # Function for rendering dashboard
 
221
 
222
 
223
  # Render the selected dashboard page
224
+ render_dashboard(page, df_filtered)