Spaces:
Sleeping
Sleeping
Update home.py
Browse files
home.py
CHANGED
@@ -1,285 +1,296 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import plotly.express as px
|
4 |
-
from wordcloud import WordCloud, STOPWORDS
|
5 |
-
import matplotlib.pyplot as plt
|
6 |
-
|
7 |
-
# Caching data loading
|
8 |
-
@st.cache_data
|
9 |
-
def load_data():
|
10 |
-
df = pd.read_csv("mafindo_mix_llm.csv")
|
11 |
-
return df
|
12 |
-
|
13 |
-
# Caching WordCloud generation
|
14 |
-
@st.cache_resource
|
15 |
-
def generate_wordcloud(text, colormap, stopwords):
|
16 |
-
wordcloud = WordCloud(width=500, height=200, background_color='white', colormap=colormap, stopwords=stopwords).generate(text)
|
17 |
-
return wordcloud
|
18 |
-
|
19 |
-
def show_home():
|
20 |
-
# Load the dataset
|
21 |
-
df = load_data()
|
22 |
-
|
23 |
-
# Convert 'Tanggal' to datetime
|
24 |
-
df['Tanggal'] = pd.to_datetime(df['Tanggal'], format='%d/%m/%Y')
|
25 |
-
df['Year'] = df['Tanggal'].dt.year
|
26 |
-
|
27 |
-
# Convert text columns to string to avoid type errors
|
28 |
-
df['Content'] = df['Content'].astype(str)
|
29 |
-
|
30 |
-
# Define additional stopwords
|
31 |
-
additional_stopwords = {"dan", "di", "yang", "ke", "dari", "untuk", "pada", "adalah", "sebuah", "dengan", "tersebut", "ini", "itu", "atau", "dalam", "juga", "adalah", "yg", "tapi"}
|
32 |
-
|
33 |
-
# Combine default stopwords with additional stopwords
|
34 |
-
combined_stopwords = set(STOPWORDS).union(additional_stopwords)
|
35 |
-
|
36 |
-
|
37 |
-
# Row with 4 visualizations
|
38 |
-
col1, col2, col3, col4 = st.columns([1.5, 2.5, 1.5, 2.5])
|
39 |
-
|
40 |
-
# Visualization 1: Bar chart for Hoax vs Non-Hoax using Plotly
|
41 |
-
with col1:
|
42 |
-
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Hoax vs Non-Hoax</h6>", unsafe_allow_html=True)
|
43 |
-
df_label_counts = df['Label'].value_counts().reset_index()
|
44 |
-
df_label_counts.columns = ['Label', 'Jumlah']
|
45 |
-
bar_chart_label = px.bar(df_label_counts, x='Label', y='Jumlah', color='Label',
|
46 |
-
color_discrete_map={'HOAX': 'red', 'NON-HOAX': 'green'})
|
47 |
-
bar_chart_label.update_layout(
|
48 |
-
width=200, height=150, xaxis_title='Label', yaxis_title='Jumlah',
|
49 |
-
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
50 |
-
xaxis_tickfont_size=8, yaxis_tickfont_size=8, margin=dict(t=10, b=10, l=10, r=10),
|
51 |
-
showlegend=False
|
52 |
-
)
|
53 |
-
st.plotly_chart(bar_chart_label, use_container_width=False)
|
54 |
-
|
55 |
-
# Visualization 2: Bar chart for Hoax vs Non-Hoax per Data Source using Plotly
|
56 |
-
with col2:
|
57 |
-
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Hoax vs Non-Hoax per Data Source</h6>", unsafe_allow_html=True)
|
58 |
-
datasource_label_counts = df.groupby(['Datasource', 'Label']).size().reset_index(name='counts')
|
59 |
-
fig_datasource = px.bar(datasource_label_counts, x='Datasource', y='counts', color='Label', barmode='group',
|
60 |
-
color_discrete_map={'HOAX': 'red', 'NON-HOAX': 'green'})
|
61 |
-
fig_datasource.update_layout(
|
62 |
-
width=500, height=150, xaxis_title='Datasource', yaxis_title='Jumlah',
|
63 |
-
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
64 |
-
xaxis_tickfont_size=6, yaxis_tickfont_size=8, xaxis_tickangle=0,
|
65 |
-
margin=dict(t=10, b=10, l=10, r=50),
|
66 |
-
legend=dict(
|
67 |
-
font=dict(size=8), # Smaller font size for the legend
|
68 |
-
traceorder='normal',
|
69 |
-
orientation='v', # Vertical orientation of the legend
|
70 |
-
title_text='Label', # Title for the legend
|
71 |
-
yanchor='top', y=1, xanchor='left', x=1.05, # Adjust position of the legend
|
72 |
-
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
73 |
-
bordercolor='rgba(0, 0, 0, 0)' # No border color
|
74 |
-
),
|
75 |
-
showlegend=True
|
76 |
-
)
|
77 |
-
st.plotly_chart(fig_datasource, use_container_width=False)
|
78 |
-
|
79 |
-
# Visualization 3: Line chart for Hoax per Year using Plotly
|
80 |
-
with col3:
|
81 |
-
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Hoax per Tahun</h6>", unsafe_allow_html=True)
|
82 |
-
|
83 |
-
# Filter data to include only years up to 2023
|
84 |
-
hoax_per_year = df[(df['Label'] == 'HOAX') & (df['Year'] <= 2023)].groupby('Year').size().reset_index(name='count')
|
85 |
-
|
86 |
-
line_chart_hoax = px.line(hoax_per_year, x='Year', y='count', line_shape='linear',
|
87 |
-
color_discrete_sequence=['red'])
|
88 |
-
line_chart_hoax.update_layout(
|
89 |
-
width=200, height=150, xaxis_title='Tahun', yaxis_title='Jumlah Hoax',
|
90 |
-
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
91 |
-
xaxis_tickfont_size=8, yaxis_tickfont_size=8, margin=dict(t=10, b=10, l=10, r=10),
|
92 |
-
showlegend=False
|
93 |
-
)
|
94 |
-
st.plotly_chart(line_chart_hoax, use_container_width=False)
|
95 |
-
|
96 |
-
|
97 |
-
# Visualization 4: Bar chart for Topics per Year using Plotly
|
98 |
-
with col4:
|
99 |
-
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Topik per Tahun</h6>", unsafe_allow_html=True)
|
100 |
-
df['Tanggal'] = pd.to_datetime(df['Tanggal'], format='%d/%m/%Y')
|
101 |
-
df['Year'] = df['Tanggal'].dt.year
|
102 |
-
|
103 |
-
# Filter the data to include only years up to 2023
|
104 |
-
df_mafindo_filtered = df[df['Year'] <= 2023]
|
105 |
-
|
106 |
-
topics_per_year = df_mafindo_filtered.groupby(['Year', 'Topic']).size().reset_index(name='count')
|
107 |
-
|
108 |
-
# Create the vertical bar chart
|
109 |
-
bar_chart_topics = px.bar(topics_per_year, x='Year', y='count', color='Topic',
|
110 |
-
color_continuous_scale=px.colors.sequential.Viridis)
|
111 |
-
|
112 |
-
# Update layout to adjust the legend
|
113 |
-
bar_chart_topics.update_layout(
|
114 |
-
width=600, height=150, xaxis_title='Tahun', yaxis_title='Jumlah Topik',
|
115 |
-
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
116 |
-
xaxis_tickfont_size=8, yaxis_tickfont_size=8, margin=dict(t=10, b=10, l=10, r=10),
|
117 |
-
showlegend=True,
|
118 |
-
legend=dict(
|
119 |
-
yanchor="top", y=1, xanchor="left", x=1.02, # Adjust position of the legend
|
120 |
-
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
121 |
-
bordercolor='rgba(0, 0, 0, 0)', # No border color
|
122 |
-
itemclick='toggleothers', # Allow toggling of legend items
|
123 |
-
itemsizing='constant', # Consistent sizing for legend items
|
124 |
-
font=dict(size=8),
|
125 |
-
traceorder='normal',
|
126 |
-
orientation='v', # Vertical orientation of legend
|
127 |
-
title_text='Topic'
|
128 |
-
)
|
129 |
-
)
|
130 |
-
|
131 |
-
st.plotly_chart(bar_chart_topics, use_container_width=True)
|
132 |
-
|
133 |
-
|
134 |
-
# Create a new row for WordCloud visualizations
|
135 |
-
col5, col6, col7 = st.columns([2, 2.5, 2.5])
|
136 |
-
|
137 |
-
# Wordcloud for Hoax
|
138 |
-
with col5:
|
139 |
-
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Wordcloud for Hoax</h6>", unsafe_allow_html=True)
|
140 |
-
hoax_text = ' '.join(df[df['Label'] == 'HOAX']['Content'])
|
141 |
-
wordcloud_hoax = generate_wordcloud(hoax_text, 'Reds', combined_stopwords)
|
142 |
-
fig_hoax = plt.figure(figsize=(5, 2.5))
|
143 |
-
plt.imshow(wordcloud_hoax, interpolation='bilinear')
|
144 |
-
plt.axis('off')
|
145 |
-
st.pyplot(fig_hoax)
|
146 |
-
|
147 |
-
with col6:
|
148 |
-
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Klasifikasi</h6>", unsafe_allow_html=True)
|
149 |
-
df_classification_counts = df['Classification'].value_counts().reset_index()
|
150 |
-
df_classification_counts.columns = ['Classification', 'Count']
|
151 |
-
|
152 |
-
# Create the donut chart
|
153 |
-
donut_chart_classification = px.pie(df_classification_counts, names='Classification', values='Count',
|
154 |
-
hole=0.3, color_discrete_sequence=px.colors.qualitative.Set2)
|
155 |
-
|
156 |
-
# Update layout to move the legend and adjust its size
|
157 |
-
donut_chart_classification.update_layout(
|
158 |
-
width=300, height=170, # Adjust the size of the chart
|
159 |
-
margin=dict(t=20, b=20, l=20, r=120), # Adjust margins to make room for the legend
|
160 |
-
legend=dict(
|
161 |
-
yanchor="top", y=1, xanchor="left", x=1.07, # Adjust position of the legend
|
162 |
-
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
163 |
-
bordercolor='rgba(0, 0, 0, 0)', # No border color
|
164 |
-
itemclick='toggleothers', # Allow toggling of legend items
|
165 |
-
itemsizing='constant', # Consistent sizing for legend items
|
166 |
-
font=dict(size=8), # Smaller font size for the legend
|
167 |
-
traceorder='normal',
|
168 |
-
orientation='v', # Vertical legend
|
169 |
-
title_text='Classification' # Title for the legend
|
170 |
-
)
|
171 |
-
)
|
172 |
-
st.plotly_chart(donut_chart_classification, use_container_width=True)
|
173 |
-
|
174 |
-
with col7:
|
175 |
-
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Tone</h6>", unsafe_allow_html=True)
|
176 |
-
df_tone_counts = df['Tone'].value_counts().reset_index()
|
177 |
-
df_tone_counts.columns = ['Tone', 'Count']
|
178 |
-
|
179 |
-
# Create the donut chart
|
180 |
-
donut_chart_tone = px.pie(df_tone_counts, names='Tone', values='Count',
|
181 |
-
hole=0.3, color_discrete_sequence=px.colors.qualitative.Set2)
|
182 |
-
|
183 |
-
# Update layout to move the legend and adjust its size
|
184 |
-
donut_chart_tone.update_layout(
|
185 |
-
width=250, height=170, # Adjust the size of the chart
|
186 |
-
margin=dict(t=20, b=20, l=20, r=100), # Adjust margins to make room for the legend
|
187 |
-
legend=dict(
|
188 |
-
yanchor="top", y=1, xanchor="left", x=1.07, # Adjust position of the legend
|
189 |
-
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
190 |
-
bordercolor='rgba(0, 0, 0, 0)', # No border color
|
191 |
-
itemclick='toggleothers', # Allow toggling of legend items
|
192 |
-
itemsizing='constant', # Consistent sizing for legend items
|
193 |
-
font=dict(size=8), # Smaller font size for the legend
|
194 |
-
traceorder='normal',
|
195 |
-
orientation='v', # Vertical legend
|
196 |
-
title_text='Tone' # Title for the legend
|
197 |
-
)
|
198 |
-
)
|
199 |
-
st.plotly_chart(donut_chart_tone, use_container_width=True)
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
["
|
206 |
-
["
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
<th
|
218 |
-
<th
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
<th style="border:
|
224 |
-
<th style="border:
|
225 |
-
<th style="border:
|
226 |
-
<th style="border:
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
html_table +=
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
<
|
266 |
-
<
|
267 |
-
<
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
<td style="padding: 8px; border: 1px solid
|
273 |
-
<td style="padding: 8px; border: 1px solid
|
274 |
-
<td style="padding: 8px; border: 1px solid
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.express as px
|
4 |
+
from wordcloud import WordCloud, STOPWORDS
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
|
7 |
+
# Caching data loading
|
8 |
+
@st.cache_data
|
9 |
+
def load_data():
|
10 |
+
df = pd.read_csv("mafindo_mix_llm.csv")
|
11 |
+
return df
|
12 |
+
|
13 |
+
# Caching WordCloud generation
|
14 |
+
@st.cache_resource
|
15 |
+
def generate_wordcloud(text, colormap, stopwords):
|
16 |
+
wordcloud = WordCloud(width=500, height=200, background_color='white', colormap=colormap, stopwords=stopwords).generate(text)
|
17 |
+
return wordcloud
|
18 |
+
|
19 |
+
def show_home():
|
20 |
+
# Load the dataset
|
21 |
+
df = load_data()
|
22 |
+
|
23 |
+
# Convert 'Tanggal' to datetime
|
24 |
+
df['Tanggal'] = pd.to_datetime(df['Tanggal'], format='%d/%m/%Y')
|
25 |
+
df['Year'] = df['Tanggal'].dt.year
|
26 |
+
|
27 |
+
# Convert text columns to string to avoid type errors
|
28 |
+
df['Content'] = df['Content'].astype(str)
|
29 |
+
|
30 |
+
# Define additional stopwords
|
31 |
+
additional_stopwords = {"dan", "di", "yang", "ke", "dari", "untuk", "pada", "adalah", "sebuah", "dengan", "tersebut", "ini", "itu", "atau", "dalam", "juga", "adalah", "yg", "tapi"}
|
32 |
+
|
33 |
+
# Combine default stopwords with additional stopwords
|
34 |
+
combined_stopwords = set(STOPWORDS).union(additional_stopwords)
|
35 |
+
|
36 |
+
|
37 |
+
# Row with 4 visualizations
|
38 |
+
col1, col2, col3, col4 = st.columns([1.5, 2.5, 1.5, 2.5])
|
39 |
+
|
40 |
+
# Visualization 1: Bar chart for Hoax vs Non-Hoax using Plotly
|
41 |
+
with col1:
|
42 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Hoax vs Non-Hoax</h6>", unsafe_allow_html=True)
|
43 |
+
df_label_counts = df['Label'].value_counts().reset_index()
|
44 |
+
df_label_counts.columns = ['Label', 'Jumlah']
|
45 |
+
bar_chart_label = px.bar(df_label_counts, x='Label', y='Jumlah', color='Label',
|
46 |
+
color_discrete_map={'HOAX': 'red', 'NON-HOAX': 'green'})
|
47 |
+
bar_chart_label.update_layout(
|
48 |
+
width=200, height=150, xaxis_title='Label', yaxis_title='Jumlah',
|
49 |
+
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
50 |
+
xaxis_tickfont_size=8, yaxis_tickfont_size=8, margin=dict(t=10, b=10, l=10, r=10),
|
51 |
+
showlegend=False
|
52 |
+
)
|
53 |
+
st.plotly_chart(bar_chart_label, use_container_width=False)
|
54 |
+
|
55 |
+
# Visualization 2: Bar chart for Hoax vs Non-Hoax per Data Source using Plotly
|
56 |
+
with col2:
|
57 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Hoax vs Non-Hoax per Data Source</h6>", unsafe_allow_html=True)
|
58 |
+
datasource_label_counts = df.groupby(['Datasource', 'Label']).size().reset_index(name='counts')
|
59 |
+
fig_datasource = px.bar(datasource_label_counts, x='Datasource', y='counts', color='Label', barmode='group',
|
60 |
+
color_discrete_map={'HOAX': 'red', 'NON-HOAX': 'green'})
|
61 |
+
fig_datasource.update_layout(
|
62 |
+
width=500, height=150, xaxis_title='Datasource', yaxis_title='Jumlah',
|
63 |
+
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
64 |
+
xaxis_tickfont_size=6, yaxis_tickfont_size=8, xaxis_tickangle=0,
|
65 |
+
margin=dict(t=10, b=10, l=10, r=50),
|
66 |
+
legend=dict(
|
67 |
+
font=dict(size=8), # Smaller font size for the legend
|
68 |
+
traceorder='normal',
|
69 |
+
orientation='v', # Vertical orientation of the legend
|
70 |
+
title_text='Label', # Title for the legend
|
71 |
+
yanchor='top', y=1, xanchor='left', x=1.05, # Adjust position of the legend
|
72 |
+
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
73 |
+
bordercolor='rgba(0, 0, 0, 0)' # No border color
|
74 |
+
),
|
75 |
+
showlegend=True
|
76 |
+
)
|
77 |
+
st.plotly_chart(fig_datasource, use_container_width=False)
|
78 |
+
|
79 |
+
# Visualization 3: Line chart for Hoax per Year using Plotly
|
80 |
+
with col3:
|
81 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Hoax per Tahun</h6>", unsafe_allow_html=True)
|
82 |
+
|
83 |
+
# Filter data to include only years up to 2023
|
84 |
+
hoax_per_year = df[(df['Label'] == 'HOAX') & (df['Year'] <= 2023)].groupby('Year').size().reset_index(name='count')
|
85 |
+
|
86 |
+
line_chart_hoax = px.line(hoax_per_year, x='Year', y='count', line_shape='linear',
|
87 |
+
color_discrete_sequence=['red'])
|
88 |
+
line_chart_hoax.update_layout(
|
89 |
+
width=200, height=150, xaxis_title='Tahun', yaxis_title='Jumlah Hoax',
|
90 |
+
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
91 |
+
xaxis_tickfont_size=8, yaxis_tickfont_size=8, margin=dict(t=10, b=10, l=10, r=10),
|
92 |
+
showlegend=False
|
93 |
+
)
|
94 |
+
st.plotly_chart(line_chart_hoax, use_container_width=False)
|
95 |
+
|
96 |
+
|
97 |
+
# Visualization 4: Bar chart for Topics per Year using Plotly
|
98 |
+
with col4:
|
99 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Topik per Tahun</h6>", unsafe_allow_html=True)
|
100 |
+
df['Tanggal'] = pd.to_datetime(df['Tanggal'], format='%d/%m/%Y')
|
101 |
+
df['Year'] = df['Tanggal'].dt.year
|
102 |
+
|
103 |
+
# Filter the data to include only years up to 2023
|
104 |
+
df_mafindo_filtered = df[df['Year'] <= 2023]
|
105 |
+
|
106 |
+
topics_per_year = df_mafindo_filtered.groupby(['Year', 'Topic']).size().reset_index(name='count')
|
107 |
+
|
108 |
+
# Create the vertical bar chart
|
109 |
+
bar_chart_topics = px.bar(topics_per_year, x='Year', y='count', color='Topic',
|
110 |
+
color_continuous_scale=px.colors.sequential.Viridis)
|
111 |
+
|
112 |
+
# Update layout to adjust the legend
|
113 |
+
bar_chart_topics.update_layout(
|
114 |
+
width=600, height=150, xaxis_title='Tahun', yaxis_title='Jumlah Topik',
|
115 |
+
xaxis_title_font_size=10, yaxis_title_font_size=10,
|
116 |
+
xaxis_tickfont_size=8, yaxis_tickfont_size=8, margin=dict(t=10, b=10, l=10, r=10),
|
117 |
+
showlegend=True,
|
118 |
+
legend=dict(
|
119 |
+
yanchor="top", y=1, xanchor="left", x=1.02, # Adjust position of the legend
|
120 |
+
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
121 |
+
bordercolor='rgba(0, 0, 0, 0)', # No border color
|
122 |
+
itemclick='toggleothers', # Allow toggling of legend items
|
123 |
+
itemsizing='constant', # Consistent sizing for legend items
|
124 |
+
font=dict(size=8),
|
125 |
+
traceorder='normal',
|
126 |
+
orientation='v', # Vertical orientation of legend
|
127 |
+
title_text='Topic'
|
128 |
+
)
|
129 |
+
)
|
130 |
+
|
131 |
+
st.plotly_chart(bar_chart_topics, use_container_width=True)
|
132 |
+
|
133 |
+
|
134 |
+
# Create a new row for WordCloud visualizations
|
135 |
+
col5, col6, col7 = st.columns([2, 2.5, 2.5])
|
136 |
+
|
137 |
+
# Wordcloud for Hoax
|
138 |
+
with col5:
|
139 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Wordcloud for Hoax</h6>", unsafe_allow_html=True)
|
140 |
+
hoax_text = ' '.join(df[df['Label'] == 'HOAX']['Content'])
|
141 |
+
wordcloud_hoax = generate_wordcloud(hoax_text, 'Reds', combined_stopwords)
|
142 |
+
fig_hoax = plt.figure(figsize=(5, 2.5))
|
143 |
+
plt.imshow(wordcloud_hoax, interpolation='bilinear')
|
144 |
+
plt.axis('off')
|
145 |
+
st.pyplot(fig_hoax)
|
146 |
+
|
147 |
+
with col6:
|
148 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Klasifikasi</h6>", unsafe_allow_html=True)
|
149 |
+
df_classification_counts = df['Classification'].value_counts().reset_index()
|
150 |
+
df_classification_counts.columns = ['Classification', 'Count']
|
151 |
+
|
152 |
+
# Create the donut chart
|
153 |
+
donut_chart_classification = px.pie(df_classification_counts, names='Classification', values='Count',
|
154 |
+
hole=0.3, color_discrete_sequence=px.colors.qualitative.Set2)
|
155 |
+
|
156 |
+
# Update layout to move the legend and adjust its size
|
157 |
+
donut_chart_classification.update_layout(
|
158 |
+
width=300, height=170, # Adjust the size of the chart
|
159 |
+
margin=dict(t=20, b=20, l=20, r=120), # Adjust margins to make room for the legend
|
160 |
+
legend=dict(
|
161 |
+
yanchor="top", y=1, xanchor="left", x=1.07, # Adjust position of the legend
|
162 |
+
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
163 |
+
bordercolor='rgba(0, 0, 0, 0)', # No border color
|
164 |
+
itemclick='toggleothers', # Allow toggling of legend items
|
165 |
+
itemsizing='constant', # Consistent sizing for legend items
|
166 |
+
font=dict(size=8), # Smaller font size for the legend
|
167 |
+
traceorder='normal',
|
168 |
+
orientation='v', # Vertical legend
|
169 |
+
title_text='Classification' # Title for the legend
|
170 |
+
)
|
171 |
+
)
|
172 |
+
st.plotly_chart(donut_chart_classification, use_container_width=True)
|
173 |
+
|
174 |
+
with col7:
|
175 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Tone</h6>", unsafe_allow_html=True)
|
176 |
+
df_tone_counts = df['Tone'].value_counts().reset_index()
|
177 |
+
df_tone_counts.columns = ['Tone', 'Count']
|
178 |
+
|
179 |
+
# Create the donut chart
|
180 |
+
donut_chart_tone = px.pie(df_tone_counts, names='Tone', values='Count',
|
181 |
+
hole=0.3, color_discrete_sequence=px.colors.qualitative.Set2)
|
182 |
+
|
183 |
+
# Update layout to move the legend and adjust its size
|
184 |
+
donut_chart_tone.update_layout(
|
185 |
+
width=250, height=170, # Adjust the size of the chart
|
186 |
+
margin=dict(t=20, b=20, l=20, r=100), # Adjust margins to make room for the legend
|
187 |
+
legend=dict(
|
188 |
+
yanchor="top", y=1, xanchor="left", x=1.07, # Adjust position of the legend
|
189 |
+
bgcolor='rgba(255, 255, 255, 0)', # Transparent background for legend
|
190 |
+
bordercolor='rgba(0, 0, 0, 0)', # No border color
|
191 |
+
itemclick='toggleothers', # Allow toggling of legend items
|
192 |
+
itemsizing='constant', # Consistent sizing for legend items
|
193 |
+
font=dict(size=8), # Smaller font size for the legend
|
194 |
+
traceorder='normal',
|
195 |
+
orientation='v', # Vertical legend
|
196 |
+
title_text='Tone' # Title for the legend
|
197 |
+
)
|
198 |
+
)
|
199 |
+
st.plotly_chart(donut_chart_tone, use_container_width=True)
|
200 |
+
|
201 |
+
col8, col9 = st.columns([5, 1.5])
|
202 |
+
|
203 |
+
# Evaluation Metrics Table
|
204 |
+
data = [
|
205 |
+
["indobenchmark/indobert-base-p2", 0.6898, 0.9793, 0.8094, 0.8400, 0.1981, 0.3206, 0.7023],
|
206 |
+
["cahya/bert-base-indonesian-522M", 0.7545, 0.8756, 0.8106, 0.6800, 0.4811, 0.5635, 0.7358],
|
207 |
+
["indolem/indobert-base-uncased", 0.7536, 0.8238, 0.7871, 0.6136, 0.5094, 0.5567, 0.7124],
|
208 |
+
["mdhugol/indonesia-bert-sentiment-classification", 0.7444, 0.8601, 0.7981, 0.6447, 0.4623, 0.5385, 0.7191]
|
209 |
+
]
|
210 |
+
|
211 |
+
highest_accuracy = max(data, key=lambda x: x[-1])
|
212 |
+
|
213 |
+
# Header Table
|
214 |
+
html_table = """
|
215 |
+
<table style="width:100%; border-collapse: collapse; font-size: 12px; border-top: 1px solid black; border-bottom: 1px solid black;">
|
216 |
+
<tr style="border-bottom: 1px solid black; text-align: center; border-top: 1px solid black;">
|
217 |
+
<th rowspan="2" style="border: none; padding: 5px; font-size: 14px; text-align: left; border-top: 1px solid black;">Pre-trained Model</th>
|
218 |
+
<th colspan="3" style="border: none; padding: 5px; font-size: 14px; text-align: center; border-top: 1px solid black;">NON-HOAX</th>
|
219 |
+
<th colspan="3" style="border: none; padding: 5px; font-size: 14px; text-align: center; border-top: 1px solid black;">HOAX</th>
|
220 |
+
<th rowspan="2" style="border: none; padding: 5px; font-size: 14px; text-align: center; border-top: 1px solid black;">Accuracy</th>
|
221 |
+
</tr>
|
222 |
+
<tr style="border-bottom: 1px solid black;">
|
223 |
+
<th style="border: none; padding: 5px; font-size: 12px; width:80px; text-align: center;">Precision</th>
|
224 |
+
<th style="border: none; padding: 5px; font-size: 12px; width:80px; text-align: center;">Recall</th>
|
225 |
+
<th style="border: none; padding: 5px; font-size: 12px; width:80px; text-align: center;">F1-Score</th>
|
226 |
+
<th style="border: none; padding: 5px; font-size: 12px; width:80px; text-align: center;">Precision</th>
|
227 |
+
<th style="border: none; padding: 5px; font-size: 12px; width:80px; text-align: center;">Recall</th>
|
228 |
+
<th style="border: none; padding: 5px; font-size: 12px; width:80px; text-align: center;">F1-Score</th>
|
229 |
+
</tr>
|
230 |
+
"""
|
231 |
+
|
232 |
+
# Isi Data
|
233 |
+
for row in data:
|
234 |
+
formatted_row = [f"{item:.4f}" if isinstance(item, float) else item for item in row]
|
235 |
+
if row == highest_accuracy:
|
236 |
+
html_table += "<tr style='background-color: #FC9576; font-size: 12px; text-align: center; border: 1px solid transparent;'>"
|
237 |
+
else:
|
238 |
+
html_table += "<tr style='font-size: 12px; text-align: center; border: 1px solid transparent;'>"
|
239 |
+
|
240 |
+
# Left-align the first column (Pre-trained Model)
|
241 |
+
html_table += f"<td style='border: none; padding: 5px; text-align: left; font-size: 12px;'>{row[0]}</td>"
|
242 |
+
|
243 |
+
# Center-align the rest of the columns
|
244 |
+
for item in formatted_row[1:]:
|
245 |
+
html_table += f"<td style='border: none; padding: 5px; text-align: center; font-size: 12px;'>{item}</td>"
|
246 |
+
|
247 |
+
html_table += "</tr>"
|
248 |
+
|
249 |
+
# Add a border to the last row
|
250 |
+
html_table += "<tr style='border-top: 1px solid black;'></tr>"
|
251 |
+
|
252 |
+
html_table += "</table>"
|
253 |
+
|
254 |
+
# Tampilkan Tabel di Streamlit
|
255 |
+
with col8:
|
256 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Matriks Evaluasi</h6>", unsafe_allow_html=True)
|
257 |
+
st.markdown(html_table, unsafe_allow_html=True)
|
258 |
+
|
259 |
+
|
260 |
+
html_table_col9 = """
|
261 |
+
<table style="width:100%; border-collapse: collapse; font-size: 12px;">
|
262 |
+
<thead>
|
263 |
+
<tr style="border-top: 1.5px solid #B2BABB; border-bottom: 1.5px solid #B2BABB;">
|
264 |
+
<th style="padding: 8px; border: 1px solid transparent; font-weight: bold; background-color: #f2f2f2; text-align: left;">Label</th>
|
265 |
+
<th style="padding: 8px; border: 1px solid transparent; font-weight: bold; background-color: #f2f2f2; text-align: center;">Train</th>
|
266 |
+
<th style="padding: 8px; border: 1px solid transparent; font-weight: bold; background-color: #f2f2f2; text-align: center;">Test</th>
|
267 |
+
<th style="padding: 8px; border: 1px solid transparent; font-weight: bold; background-color: #f2f2f2; text-align: center;">Dev</th>
|
268 |
+
</tr>
|
269 |
+
</thead>
|
270 |
+
<tbody>
|
271 |
+
<tr style="border-bottom: 1px solid transparent;">
|
272 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2;">HOAX</td>
|
273 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">11.563</td>
|
274 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">193</td>
|
275 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">193</td>
|
276 |
+
</tr>
|
277 |
+
<tr style="border-bottom: 1px solid black;">
|
278 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2;">NON-HOAX</td>
|
279 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">789</td>
|
280 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">106</td>
|
281 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">106</td>
|
282 |
+
</tr>
|
283 |
+
<tr style="font-weight: bold; border-top: 1px solid transparent; border-bottom: 1.5px solid #B2BABB;">
|
284 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2;">TOTAL</td>
|
285 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">12,352</td>
|
286 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">299</td>
|
287 |
+
<td style="padding: 8px; border: 1px solid transparent; background-color: #f2f2f2; text-align: center;">299</td>
|
288 |
+
</tr>
|
289 |
+
</tbody>
|
290 |
+
</table>
|
291 |
+
"""
|
292 |
+
|
293 |
+
# Display the table in col9 using HTML
|
294 |
+
with col9:
|
295 |
+
st.markdown("<h6 style='font-size: 14px; margin-bottom: 0;'>Statistik Data</h6>", unsafe_allow_html=True)
|
296 |
+
st.markdown(html_table_col9, unsafe_allow_html=True)
|