Update app.py
Browse files
app.py
CHANGED
@@ -10,44 +10,52 @@ import plotly.graph_objects as go
|
|
10 |
# Set page configuration
|
11 |
st.set_page_config(layout="wide")
|
12 |
|
13 |
-
|
14 |
def load_and_clean_data():
|
|
|
15 |
df1 = pd.read_csv("data/reviewed_social_media_english.csv")
|
16 |
df2 = pd.read_csv("data/reviewed_news_english.csv")
|
17 |
df3 = pd.read_csv("data/tamil_social_media.csv")
|
18 |
df4 = pd.read_csv("data/tamil_news.csv")
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
df_combined =
|
|
|
31 |
return df_combined
|
32 |
|
|
|
33 |
df = load_and_clean_data()
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
#
|
42 |
-
|
43 |
-
for df in frames:
|
44 |
-
df = df[df['Domain'] != 'Not relevant']
|
45 |
-
df = df[df['Domain'] != 'None']
|
46 |
-
df = df[df['Discrimination'] != 'None']
|
47 |
-
df = df[df['Sentiment'] != 'None']
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
|
52 |
# Visualization function
|
53 |
def create_visualizations(df):
|
@@ -116,22 +124,6 @@ def render_dashboard():
|
|
116 |
|
117 |
# ... [Other pages]
|
118 |
|
119 |
-
# Define Sidebar Filters
|
120 |
-
domain_options = df['Domain'].unique()
|
121 |
-
channel_options = df['Channel'].unique()
|
122 |
-
sentiment_options = df['Sentiment'].unique()
|
123 |
-
discrimination_options = df['Discrimination'].unique()
|
124 |
-
|
125 |
-
domain_filter = st.sidebar.multiselect('Select Domain', options=domain_options, default=domain_options)
|
126 |
-
channel_filter = st.sidebar.multiselect('Select Channel', options=channel_options, default=channel_options)
|
127 |
-
sentiment_filter = st.sidebar.multiselect('Select Sentiment', options=sentiment_options, default=sentiment_options)
|
128 |
-
discrimination_filter = st.sidebar.multiselect('Select Discrimination', options=discrimination_options, default=discrimination_options)
|
129 |
-
|
130 |
-
# Apply the filters to the dataframe
|
131 |
-
df_filtered = df[(df['Domain'].isin(domain_filter)) &
|
132 |
-
(df['Channel'].isin(channel_filter)) &
|
133 |
-
(df['Sentiment'].isin(sentiment_filter)) &
|
134 |
-
(df['Discrimination'].isin(discrimination_filter))]
|
135 |
|
136 |
# Render the dashboard with filtered data
|
137 |
render_dashboard(df_filtered)
|
|
|
10 |
# Set page configuration
|
11 |
st.set_page_config(layout="wide")
|
12 |
|
|
|
13 |
def load_and_clean_data():
|
14 |
+
# Load data
|
15 |
df1 = pd.read_csv("data/reviewed_social_media_english.csv")
|
16 |
df2 = pd.read_csv("data/reviewed_news_english.csv")
|
17 |
df3 = pd.read_csv("data/tamil_social_media.csv")
|
18 |
df4 = pd.read_csv("data/tamil_news.csv")
|
19 |
|
20 |
+
# Concatenate dataframes
|
21 |
+
df_combined = pd.concat([df1, df2, df3, df4])
|
22 |
+
|
23 |
+
# Normalize Text
|
24 |
+
df_combined['Domain'] = df_combined['Domain'].replace("MUSLIM", "Muslim")
|
25 |
+
|
26 |
+
# Drop irrelevant data
|
27 |
+
df_combined = df_combined[df_combined['Domain'] != 'Not relevant']
|
28 |
+
df_combined = df_combined[df_combined['Domain'] != 'None']
|
29 |
+
df_combined = df_combined[df_combined['Discrimination'] != 'None']
|
30 |
+
df_combined = df_combined[df_combined['Sentiment'] != 'None']
|
31 |
+
|
32 |
return df_combined
|
33 |
|
34 |
+
# Load and clean data
|
35 |
df = load_and_clean_data()
|
36 |
|
37 |
+
# Define Sidebar Filters
|
38 |
+
domain_options = df['Domain'].unique()
|
39 |
+
channel_options = df['Channel'].unique()
|
40 |
+
sentiment_options = df['Sentiment'].unique()
|
41 |
+
discrimination_options = df['Discrimination'].unique()
|
42 |
+
|
43 |
+
domain_filter = st.sidebar.multiselect('Select Domain', options=domain_options, default=domain_options)
|
44 |
+
channel_filter = st.sidebar.multiselect('Select Channel', options=channel_options, default=channel_options)
|
45 |
+
sentiment_filter = st.sidebar.multiselect('Select Sentiment', options=sentiment_options, default=sentiment_options)
|
46 |
+
discrimination_filter = st.sidebar.multiselect('Select Discrimination', options=discrimination_options, default=discrimination_options)
|
47 |
+
|
48 |
+
# Apply the filters to the dataframe
|
49 |
+
df_filtered = df[(df['Domain'].isin(domain_filter)) &
|
50 |
+
(df['Channel'].isin(channel_filter)) &
|
51 |
+
(df['Sentiment'].isin(sentiment_filter)) &
|
52 |
+
(df['Discrimination'].isin(discrimination_filter))]
|
53 |
|
54 |
+
# Page navigation
|
55 |
+
page = st.sidebar.selectbox("Choose a page", ["Overview", "Sentiment Analysis", "Discrimination Analysis", "Channel Analysis"])
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
# Define a color palette for consistent visualization styles
|
58 |
+
color_palette = px.colors.sequential.Viridis
|
59 |
|
60 |
# Visualization function
|
61 |
def create_visualizations(df):
|
|
|
124 |
|
125 |
# ... [Other pages]
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
# Render the dashboard with filtered data
|
129 |
render_dashboard(df_filtered)
|