Spaces:
Sleeping
Sleeping
Update index.py
Browse files
index.py
CHANGED
@@ -128,10 +128,24 @@ app.layout = dbc.Container([
|
|
128 |
dbc.Row([ # row 11
|
129 |
dbc.Col(dcc.Graph(id='line-graph-4'),
|
130 |
)
|
131 |
-
])
|
132 |
|
133 |
-
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
# callback decorator
|
136 |
@app.callback(
|
137 |
Output('line-graph-1', 'figure'),
|
@@ -139,6 +153,7 @@ app.layout = dbc.Container([
|
|
139 |
Output('line-graph-2', 'figure'),
|
140 |
Output('line-graph-3', 'figure'),
|
141 |
Output('line-graph-4', 'figure'),
|
|
|
142 |
Input("topic-selector", "value"),
|
143 |
Input ("domain-selector", "value"),
|
144 |
Input('date-range', 'start_date'),
|
@@ -226,10 +241,63 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
|
|
226 |
line_fig_2.update_traces(line_color='#1E88E5')
|
227 |
line_fig_3.update_traces(line_color='#004D40')
|
228 |
line_fig_4.update_traces(line_color='#D81B60')
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
else:
|
232 |
-
return {'data': []},{'data': []} ,{'data': []} ,{'data': []} , {'data': []}
|
233 |
|
234 |
# return line_fig_1
|
235 |
|
|
|
128 |
dbc.Row([ # row 11
|
129 |
dbc.Col(dcc.Graph(id='line-graph-4'),
|
130 |
)
|
131 |
+
]),
|
132 |
|
133 |
+
html.Div(id='pie-container-1')
|
134 |
|
135 |
+
])
|
136 |
+
# # Create a function to generate pie charts
|
137 |
+
# def generate_pie_chart(category):
|
138 |
+
# labels = data[category]['labels']
|
139 |
+
# values = data[category]['values']
|
140 |
+
# trace = go.Pie(labels=labels, values=values)
|
141 |
+
# layout = go.Layout(title=f'Pie Chart - {category}')
|
142 |
+
# return dcc.Graph(
|
143 |
+
# figure={
|
144 |
+
# 'data': [trace],
|
145 |
+
# 'layout': layout
|
146 |
+
# }
|
147 |
+
# )
|
148 |
+
|
149 |
# callback decorator
|
150 |
@app.callback(
|
151 |
Output('line-graph-1', 'figure'),
|
|
|
153 |
Output('line-graph-2', 'figure'),
|
154 |
Output('line-graph-3', 'figure'),
|
155 |
Output('line-graph-4', 'figure'),
|
156 |
+
Output('pie-container-1', 'children'),
|
157 |
Input("topic-selector", "value"),
|
158 |
Input ("domain-selector", "value"),
|
159 |
Input('date-range', 'start_date'),
|
|
|
241 |
line_fig_2.update_traces(line_color='#1E88E5')
|
242 |
line_fig_3.update_traces(line_color='#004D40')
|
243 |
line_fig_4.update_traces(line_color='#D81B60')
|
244 |
+
|
245 |
+
#
|
246 |
+
# pie_container_1 = generate_pie_chart(category)
|
247 |
+
# Map original labels to their translated versions
|
248 |
+
label_translation = {'positive': 'positivo', 'neutral': 'neutro', 'negative': 'negativo'}
|
249 |
+
df_filtered['FinBERT_label_transformed'] = df_filtered['FinBERT_label'].map(label_translation)
|
250 |
+
|
251 |
+
# Group by FinBERT_label and count occurrences
|
252 |
+
label_counts_all = df_filtered['FinBERT_label_transformed'].value_counts()
|
253 |
+
|
254 |
+
# Calculate percentage of each label
|
255 |
+
label_percentages_all = (label_counts_all / label_counts_all.sum()) * 100
|
256 |
+
|
257 |
+
# Plot general pie chart
|
258 |
+
fig_general = px.pie(
|
259 |
+
values=label_percentages_all,
|
260 |
+
names=label_percentages_all.index,
|
261 |
+
title='Distribuição Geral',
|
262 |
+
color_discrete_sequence=['#039a4d', '#3c03f4', '#ca3919']
|
263 |
+
)
|
264 |
+
|
265 |
+
|
266 |
+
# Get unique media categories
|
267 |
+
media_categories = df_filtered['Veículos de notícias'].unique()
|
268 |
+
|
269 |
+
# Define colors for each label
|
270 |
+
label_colors = {'positivo': '#039a4d', 'neutro': '#3c03f4', 'negativo': '#ca3919'}
|
271 |
+
|
272 |
+
|
273 |
+
pie_container_1 = []
|
274 |
+
for row in range(num_rows):
|
275 |
+
row_content = []
|
276 |
+
# Loop through each media category
|
277 |
+
for media in media_categories:
|
278 |
+
# Filter DataFrame for current media category
|
279 |
+
media_df = df[df['Veículos de notícias'] == media]
|
280 |
+
|
281 |
+
# Group by FinBERT_label and count occurrences
|
282 |
+
label_counts = media_df['FinBERT_label_transformed'].value_counts()
|
283 |
+
|
284 |
+
# Calculate percentage of each label
|
285 |
+
label_percentages = (label_counts / label_counts.sum()) * 100
|
286 |
+
|
287 |
+
# Plot pie chart
|
288 |
+
fig = px.pie(
|
289 |
+
values=label_percentages,
|
290 |
+
names=label_percentages.index,
|
291 |
+
title=f'Distribuição para {media}',
|
292 |
+
color_discrete_sequence=[label_colors[label] for label in label_percentages.index]
|
293 |
+
)
|
294 |
+
pie_chart = html.Div(fig)
|
295 |
+
row_content.append(pie_chart)
|
296 |
+
pie_container_1.append(html.Div(row_content, className='row'))
|
297 |
+
|
298 |
+
return line_fig_1, bar_fig_1, line_fig_2, line_fig_3, line_fig_4, pie_container_1
|
299 |
else:
|
300 |
+
return {'data': []},{'data': []} ,{'data': []} ,{'data': []} , {'data': []}, {'data':[]}
|
301 |
|
302 |
# return line_fig_1
|
303 |
|