Update app.py
Browse files
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=
|
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=
|
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=
|
83 |
return fig
|
84 |
|
85 |
# Visualization for Correlation between Sentiment and Discrimination
|
@@ -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=
|
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=
|
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=
|
126 |
return fig
|
127 |
|
128 |
# Function for Prevalence of Discriminatory Content Chart
|
@@ -141,21 +141,21 @@ def create_top_discriminatory_domains_chart(df):
|
|
141 |
domain_counts_subset = domain_counts_subset.rename(columns={'Discriminative': 'Count'})
|
142 |
fig = px.bar(domain_counts_subset, x='Count', y=domain_counts_subset.index, orientation='h',
|
143 |
title='Top Domains with Discriminatory Content')
|
144 |
-
fig.update_layout(margin=dict(l=
|
145 |
return fig
|
146 |
|
147 |
# Function for Channel-wise Sentiment Over Time Chart
|
148 |
def create_sentiment_distribution_by_channel_chart(df):
|
149 |
sentiment_by_channel = df.groupby(['Channel', 'Sentiment']).size().reset_index(name='counts')
|
150 |
fig = px.bar(sentiment_by_channel, x='Channel', y='counts', color='Sentiment', title="Sentiment Distribution by Channel", barmode='group')
|
151 |
-
fig.update_layout(margin=dict(l=
|
152 |
return fig
|
153 |
|
154 |
# Function for Channel-wise Distribution of Discriminative Content Chart
|
155 |
def create_channel_discrimination_chart(df):
|
156 |
channel_discrimination = df.groupby(['Channel', 'Discrimination']).size().unstack(fill_value=0)
|
157 |
fig = px.bar(channel_discrimination, x=channel_discrimination.index, y=['Discriminative', 'Non-Discriminative'], barmode='group')
|
158 |
-
fig.update_layout(title='Channel-wise Distribution of Discriminative Content', margin=dict(l=
|
159 |
return fig
|
160 |
|
161 |
# Function for rendering dashboard
|
|
|
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=10, r=10, t=20, b=10), legend=dict(x=0.1, y=1), font=dict(size=10))
|
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=10, r=10, t=20, b=10), legend=dict(x=0.1, y=1), font=dict(size=10))
|
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=10, r=10, t=20, b=10), xaxis_title="Domain", yaxis_title="Counts", font=dict(size=10))
|
83 |
return fig
|
84 |
|
85 |
# Visualization for Correlation between Sentiment and Discrimination
|
|
|
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=10, r=10, t=20, b=10), xaxis_title="Sentiment", yaxis_title="Count", font=dict(size=10))
|
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=10, r=10, t=20, b=10), xaxis_title="Negative sentiment content Count", yaxis_title="Domain")
|
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=10, r=10, t=20, b=10), xaxis_title="Frequency", yaxis_title="Trigram")
|
126 |
return fig
|
127 |
|
128 |
# Function for Prevalence of Discriminatory Content Chart
|
|
|
141 |
domain_counts_subset = domain_counts_subset.rename(columns={'Discriminative': 'Count'})
|
142 |
fig = px.bar(domain_counts_subset, x='Count', y=domain_counts_subset.index, orientation='h',
|
143 |
title='Top Domains with Discriminatory Content')
|
144 |
+
fig.update_layout(margin=dict(l=10, r=10, t=20, b=10), xaxis_title="Discriminatory Content Count", yaxis_title="Domain")
|
145 |
return fig
|
146 |
|
147 |
# Function for Channel-wise Sentiment Over Time Chart
|
148 |
def create_sentiment_distribution_by_channel_chart(df):
|
149 |
sentiment_by_channel = df.groupby(['Channel', 'Sentiment']).size().reset_index(name='counts')
|
150 |
fig = px.bar(sentiment_by_channel, x='Channel', y='counts', color='Sentiment', title="Sentiment Distribution by Channel", barmode='group')
|
151 |
+
fig.update_layout(margin=dict(l=10, r=10, t=20, b=10), xaxis_title="Channel", yaxis_title="Counts", font=dict(size=10))
|
152 |
return fig
|
153 |
|
154 |
# Function for Channel-wise Distribution of Discriminative Content Chart
|
155 |
def create_channel_discrimination_chart(df):
|
156 |
channel_discrimination = df.groupby(['Channel', 'Discrimination']).size().unstack(fill_value=0)
|
157 |
fig = px.bar(channel_discrimination, x=channel_discrimination.index, y=['Discriminative', 'Non-Discriminative'], barmode='group')
|
158 |
+
fig.update_layout(title='Channel-wise Distribution of Discriminative Content', margin=dict(l=10, r=10, t=20, b=10))
|
159 |
return fig
|
160 |
|
161 |
# Function for rendering dashboard
|