thak123 commited on
Commit
8a6fd41
·
verified ·
1 Parent(s): 2e97672

Update index.py

Browse files
Files changed (1) hide show
  1. index.py +42 -39
index.py CHANGED
@@ -57,7 +57,7 @@ df_neg = counts[[x in ['negative'] for x in counts.FinBERT_label]]
57
 
58
 
59
  # app.layout
60
- tab_content_1 = dbc.Container([
61
  dbc.Row([ # row 1
62
  dbc.Col([html.H1('Evolução temporal de sentimento em títulos de notícias')],
63
  className="text-center mt-3 mb-1")]),
@@ -149,7 +149,9 @@ tab_content_1 = dbc.Container([
149
  dbc.Col(dcc.Graph(id='pie-graph-2'),
150
  )
151
  ]),
152
-
 
 
153
  dbc.Row([ # row 9
154
  dbc.Col(
155
  dash_table.DataTable(
@@ -294,19 +296,20 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
294
  # Calculate percentage of each label
295
  label_percentages_all = (label_counts_all / label_counts_all.sum()) * 100
296
 
 
 
297
  # Plot general pie chart
298
  pie_chart_1 = px.pie(
299
  values=label_percentages_all,
300
  names=label_percentages_all.index,
301
  title='Distribuição Geral',
302
- color_discrete_sequence=['#039a4d', '#3c03f4', '#ca3919']
303
  )
304
 
305
  # Get unique media categories
306
  media_categories = df_filtered['Veículos de notícias'].unique()
307
 
308
- # Define colors for each label
309
- label_colors = {'positivo': '#039a4d', 'neutro': '#3c03f4', 'negativo': '#ca3919'}
310
 
311
  # Filter DataFrame for current media category
312
  media_df = df_filtered[df_filtered['Veículos de notícias'] == selected_domain]
@@ -333,7 +336,7 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
333
  ordered=True)
334
 
335
  # Sort DataFrame by sentiment label and date
336
- data_table_1 = media_df.sort_values(by=['FinBERT_label', 'date'])
337
 
338
  return line_fig_1, bar_fig_1, pie_chart_1, line_fig_2, pie_chart_2, data_table_1.to_dict('records')
339
  else:
@@ -371,40 +374,40 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
371
  # )
372
  # def update_headlines_table(selected_topic, selected_domain, start_date, end_date):
373
  # # Filtering data...
374
- tab_content_2 = dcc.Markdown('''
375
-
376
- # Sobre o projeto
377
-
378
-
379
- ''')
380
-
381
- app.layout = html.Div(
382
- [
383
- dbc.Card(
384
- [
385
- dbc.CardHeader(
386
- dbc.Tabs(
387
- [
388
- dbc.Tab(label="SentDiário", tab_id="tab-1"),
389
- dbc.Tab(label="Sobre o projeto", tab_id="tab-2"),
390
- ],
391
- id="tabs",
392
- active_tab="tab-1",
393
- )
394
- ),
395
- dbc.CardBody(html.Div(id="content", className="card-text")),
396
- ]
397
- )
398
- ]
399
- )
400
 
401
- @app.callback(Output("content", "children"), [Input("tabs", "active_tab")])
402
- def switch_tab(at):
403
- if at == "tab-1":
404
- return tab_content_1
405
- elif at == "tab-2":
406
- return tab_content_2
407
- return html.P("This shouldn't ever be displayed...")
408
 
409
  if __name__ == '__main__':
410
  app.run_server(debug=True)
 
57
 
58
 
59
  # app.layout
60
+ app.layout = dbc.Container([
61
  dbc.Row([ # row 1
62
  dbc.Col([html.H1('Evolução temporal de sentimento em títulos de notícias')],
63
  className="text-center mt-3 mb-1")]),
 
149
  dbc.Col(dcc.Graph(id='pie-graph-2'),
150
  )
151
  ]),
152
+ dbc.Row([ # row
153
+ dbc.Label('Lista de notícias encontradas para o tópico e meio de comunicação selecionados', className="fw-bold")
154
+ ]),
155
  dbc.Row([ # row 9
156
  dbc.Col(
157
  dash_table.DataTable(
 
296
  # Calculate percentage of each label
297
  label_percentages_all = (label_counts_all / label_counts_all.sum()) * 100
298
 
299
+ # Define colors for each label
300
+ label_colors = {'positivo': '#039a4d', 'neutro': '#3c03f4', 'negativo': '#ca3919'}
301
  # Plot general pie chart
302
  pie_chart_1 = px.pie(
303
  values=label_percentages_all,
304
  names=label_percentages_all.index,
305
  title='Distribuição Geral',
306
+ color_discrete_sequence=[label_colors[label] for label in label_percentages_all.index] #['#039a4d', '#3c03f4', '#ca3919']
307
  )
308
 
309
  # Get unique media categories
310
  media_categories = df_filtered['Veículos de notícias'].unique()
311
 
312
+
 
313
 
314
  # Filter DataFrame for current media category
315
  media_df = df_filtered[df_filtered['Veículos de notícias'] == selected_domain]
 
336
  ordered=True)
337
 
338
  # Sort DataFrame by sentiment label and date
339
+ data_table_1 = media_df.sort_values(by=['date', "FinBERT_label"])
340
 
341
  return line_fig_1, bar_fig_1, pie_chart_1, line_fig_2, pie_chart_2, data_table_1.to_dict('records')
342
  else:
 
374
  # )
375
  # def update_headlines_table(selected_topic, selected_domain, start_date, end_date):
376
  # # Filtering data...
377
+ # tab_content_2 = dcc.Markdown('''
378
+
379
+ # # Sobre o projeto
380
+
381
+
382
+ # ''')
383
+
384
+ # app.layout = html.Div(
385
+ # [
386
+ # dbc.Card(
387
+ # [
388
+ # dbc.CardHeader(
389
+ # dbc.Tabs(
390
+ # [
391
+ # dbc.Tab(label="SentDiário", tab_id="tab-1"),
392
+ # dbc.Tab(label="Sobre o projeto", tab_id="tab-2"),
393
+ # ],
394
+ # id="tabs",
395
+ # active_tab="tab-1",
396
+ # )
397
+ # ),
398
+ # dbc.CardBody(html.Div(id="content", className="card-text")),
399
+ # ]
400
+ # )
401
+ # ]
402
+ # )
403
 
404
+ # @app.callback(Output("content", "children"), [Input("tabs", "active_tab")])
405
+ # def switch_tab(at):
406
+ # if at == "tab-1":
407
+ # return tab_content_1
408
+ # elif at == "tab-2":
409
+ # return tab_content_2
410
+ # return html.P("This shouldn't ever be displayed...")
411
 
412
  if __name__ == '__main__':
413
  app.run_server(debug=True)