Spaces:
Sleeping
Sleeping
Update index.py
Browse files
index.py
CHANGED
@@ -47,38 +47,35 @@ df['FinBERT_label'].replace({
|
|
47 |
counts = df.groupby(['date', 'Topic', 'domain_folder_name', 'FinBERT_label']).size().reset_index(name='count')
|
48 |
counts['count'] = counts['count'].astype('float64')
|
49 |
counts['rolling_mean_counts'] = counts['count'].rolling(window=30, min_periods=2).mean()
|
|
|
50 |
df_pos = counts[[x in ['positive'] for x in counts.FinBERT_label]]
|
51 |
df_neu = counts[[x in ['neutral'] for x in counts.FinBERT_label]]
|
52 |
df_neg = counts[[x in ['negative'] for x in counts.FinBERT_label]]
|
53 |
|
54 |
|
55 |
|
56 |
-
app.layout = dbc.Container(
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
),
|
62 |
dbc.Row([ # row 2
|
63 |
-
dbc.Label("Selecione um período (mm/dd/aaaa):", className="fw-bold")
|
64 |
-
]),
|
65 |
|
66 |
-
dbc.Row([ # row 3
|
67 |
dcc.DatePickerRange(
|
68 |
id='date-range',
|
69 |
min_date_allowed=df['date'].min().date(),
|
70 |
max_date_allowed=df['date'].max().date(),
|
71 |
initial_visible_month=df['date'].min().date(),
|
72 |
start_date=df['date'].min().date(),
|
73 |
-
end_date=df['date'].max().date()
|
74 |
-
)
|
75 |
-
]),
|
76 |
|
77 |
dbc.Row([ # row 4
|
78 |
dbc.Label("Escolha um tópico:", className="fw-bold")
|
79 |
-
]),
|
80 |
|
81 |
-
dbc.Row([ # row 5
|
82 |
dbc.Col(
|
83 |
dcc.Dropdown(
|
84 |
id="topic-selector",
|
@@ -91,17 +88,16 @@ dbc.Row([ # row 5
|
|
91 |
|
92 |
)
|
93 |
]),
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
dbc.Row([ # row
|
96 |
-
|
97 |
-
|
98 |
-
]),
|
99 |
-
|
100 |
-
dbc.Row([ # row 7
|
101 |
-
dbc.Label("Escolha um site de notícias:", className="fw-bold")
|
102 |
-
]),
|
103 |
|
104 |
-
dbc.Row([ # row 8
|
105 |
dbc.Col(
|
106 |
dcc.Dropdown(
|
107 |
id="domain-selector",
|
@@ -115,20 +111,20 @@ dbc.Row([ # row 8
|
|
115 |
)
|
116 |
]),
|
117 |
|
118 |
-
dbc.Row([ # row 9
|
119 |
-
|
120 |
-
|
121 |
-
]),
|
122 |
-
|
123 |
-
dbc.Row([ # row 10
|
124 |
-
dbc.Col(dcc.Graph(id='line-graph-3'),
|
125 |
-
)
|
126 |
-
]),
|
127 |
|
128 |
-
dbc.Row([ # row
|
129 |
-
|
130 |
-
|
131 |
-
])
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
])
|
134 |
|
@@ -143,13 +139,11 @@ dbc.Row([ # row 11
|
|
143 |
Input('date-range', 'start_date'),
|
144 |
Input('date-range', 'end_date')
|
145 |
)
|
146 |
-
# callback function
|
147 |
def update_output(selected_topic, selected_domain, start_date, end_date):
|
148 |
# filter dataframes based on updated data range
|
149 |
mask_1 = ((df["Topic"] == selected_topic) & (df['date'] >= start_date) & (df['date'] <= end_date))
|
150 |
df_filtered = df.loc[mask_1]
|
151 |
|
152 |
-
|
153 |
#create line graphs based on filtered dataframes
|
154 |
line_fig_1 = px.line(df_filtered, x="date", y="normalised results",
|
155 |
color='Veículos de notícias', title="O gráfico mostra a evolução temporal de sentimento dos títulos de notícias. Numa escala de -1 (negativo) a 1 (positivo), sendo 0 (neutro).")
|
|
|
47 |
counts = df.groupby(['date', 'Topic', 'domain_folder_name', 'FinBERT_label']).size().reset_index(name='count')
|
48 |
counts['count'] = counts['count'].astype('float64')
|
49 |
counts['rolling_mean_counts'] = counts['count'].rolling(window=30, min_periods=2).mean()
|
50 |
+
|
51 |
df_pos = counts[[x in ['positive'] for x in counts.FinBERT_label]]
|
52 |
df_neu = counts[[x in ['neutral'] for x in counts.FinBERT_label]]
|
53 |
df_neg = counts[[x in ['negative'] for x in counts.FinBERT_label]]
|
54 |
|
55 |
|
56 |
|
57 |
+
app.layout = dbc.Container([
|
58 |
+
dbc.Row([ # row 1
|
59 |
+
dbc.Col([html.H1('Evolução temporal de sentimento em títulos de notícias')],
|
60 |
+
className="text-center mt-3 mb-1")]),
|
61 |
+
|
|
|
62 |
dbc.Row([ # row 2
|
63 |
+
dbc.Label("Selecione um período (mm/dd/aaaa):", className="fw-bold")]),
|
|
|
64 |
|
65 |
+
dbc.Row([ # row 3
|
66 |
dcc.DatePickerRange(
|
67 |
id='date-range',
|
68 |
min_date_allowed=df['date'].min().date(),
|
69 |
max_date_allowed=df['date'].max().date(),
|
70 |
initial_visible_month=df['date'].min().date(),
|
71 |
start_date=df['date'].min().date(),
|
72 |
+
end_date=df['date'].max().date())]),
|
|
|
|
|
73 |
|
74 |
dbc.Row([ # row 4
|
75 |
dbc.Label("Escolha um tópico:", className="fw-bold")
|
76 |
+
]),
|
77 |
|
78 |
+
dbc.Row([ # row 5
|
79 |
dbc.Col(
|
80 |
dcc.Dropdown(
|
81 |
id="topic-selector",
|
|
|
88 |
|
89 |
)
|
90 |
]),
|
91 |
+
|
92 |
+
dbc.Row([ # row 6
|
93 |
+
dbc.Col(dcc.Graph(id='line-graph-1'))
|
94 |
+
]),
|
95 |
|
96 |
+
dbc.Row([ # row 7
|
97 |
+
dbc.Label("Escolha um site de notícias:", className="fw-bold")
|
98 |
+
]),
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
+
dbc.Row([ # row 8
|
101 |
dbc.Col(
|
102 |
dcc.Dropdown(
|
103 |
id="domain-selector",
|
|
|
111 |
)
|
112 |
]),
|
113 |
|
114 |
+
dbc.Row([ # row 9
|
115 |
+
dbc.Col(dcc.Graph(id='line-graph-2'),
|
116 |
+
)
|
117 |
+
]),
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
+
dbc.Row([ # row 10
|
120 |
+
dbc.Col(dcc.Graph(id='line-graph-3'),
|
121 |
+
)
|
122 |
+
]),
|
123 |
+
|
124 |
+
dbc.Row([ # row 11
|
125 |
+
dbc.Col(dcc.Graph(id='line-graph-4'),
|
126 |
+
)
|
127 |
+
])
|
128 |
|
129 |
])
|
130 |
|
|
|
139 |
Input('date-range', 'start_date'),
|
140 |
Input('date-range', 'end_date')
|
141 |
)
|
|
|
142 |
def update_output(selected_topic, selected_domain, start_date, end_date):
|
143 |
# filter dataframes based on updated data range
|
144 |
mask_1 = ((df["Topic"] == selected_topic) & (df['date'] >= start_date) & (df['date'] <= end_date))
|
145 |
df_filtered = df.loc[mask_1]
|
146 |
|
|
|
147 |
#create line graphs based on filtered dataframes
|
148 |
line_fig_1 = px.line(df_filtered, x="date", y="normalised results",
|
149 |
color='Veículos de notícias', title="O gráfico mostra a evolução temporal de sentimento dos títulos de notícias. Numa escala de -1 (negativo) a 1 (positivo), sendo 0 (neutro).")
|