SelmaNajih001 commited on
Commit
c74c4e2
·
verified ·
1 Parent(s): b52d2fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -36
app.py CHANGED
@@ -154,55 +154,64 @@ def show_sentiment(selected_companies=None, aggregation="Day", selected_year="Al
154
  import gradio as gr
155
 
156
  # Markdown descrittivo adattato al tuo dashboard
 
 
 
157
  description_text = """
158
- ### How This Dashboard Works
159
 
160
- This dashboard allows you to explore the sentiment of news articles related to major tech companies (Apple, Tesla, Microsoft, Meta, Alphabet) and compare it with their stock prices.
161
 
162
- - **Multiple companies per news**: Some news articles mention more than one company. Each news item is associated with the relevant companies in the dataset, allowing you to analyze sentiment per company.
163
- - **Dataset structure**: The dataset includes a company column and is organized so that each row corresponds to a news item for a specific company. This ensures accurate aggregation of sentiment scores while avoiding duplicate rows.
164
- - **Sentiment aggregation**: You can select a time aggregation level (Month or Year) to see how sentiment evolves over time.
165
  - **NASDAQ comparison**: Selecting "NASDAQ" shows the general market sentiment alongside the company-specific sentiment.
166
- - **Visual insights**: The top-left graph shows the average sentiment score and the corresponding closing price of the selected company. Similar trends are often observed between sentiment and stock performance.
167
- - **Multiple companies and years**: You can filter by company and year to focus on specific periods, or leave as "All" for a broader overview.
168
-
169
  """
170
 
171
- # Lista di aziende e anni
172
  companies = sorted(df['Company'].unique().tolist()) + ["NASDAQ"]
173
  years = sorted(df['Year'].dropna().unique().tolist())
174
 
175
- # Interfaccia a colonne
176
  with gr.Blocks() as demo:
 
177
  gr.Markdown("# Dynamic Sentiment Dashboard")
 
178
 
 
179
  with gr.Row():
180
- # Colonna a sinistra: Markdown
181
- with gr.Column(scale=1):
182
- gr.Markdown(description_text)
183
-
184
- # Colonna a destra: Input
185
- with gr.Column(scale=2):
186
- dropdown_companies = gr.Dropdown(
187
- choices=companies,
188
- value=None,
189
- label="Select Companies (NASDAQ compares with general sentiment)",
190
- multiselect=False
191
- )
192
 
193
- radio_aggregation = gr.Radio(
194
- choices=["Month", "Year"],
195
- value="Month",
196
- label="Aggregation Level"
197
- )
198
 
199
- dropdown_year = gr.Dropdown(
200
- choices=["All"] + years,
201
- value=2022,
202
- label="Select Year"
203
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
- # Output sotto le colonne
206
- gr.Dataframe(label="Sentiment Table", type="pandas")
207
- gr.Plot(label="Sentiment Trend")
208
- demo.launch()
 
154
  import gradio as gr
155
 
156
  # Markdown descrittivo adattato al tuo dashboard
157
+ import gradio as gr
158
+
159
+ # --- Markdown descrittivo ---
160
  description_text = """
161
+ ### Dynamic Sentiment Dashboard
162
 
163
+ This dashboard allows you to explore the sentiment of news articles related to major tech companies (Apple, Tesla, Microsoft, Meta, Alphabet) and compare it with their stock prices.
164
 
165
+ - **Multiple companies per news**: Some news articles mention more than one company. Each news item is associated with the relevant companies in the dataset.
166
+ - **Dataset structure**: The dataset includes a company column; each row corresponds to a news item for a specific company.
167
+ - **Sentiment aggregation**: Select a time aggregation level (Month or Year) to see how sentiment evolves over time.
168
  - **NASDAQ comparison**: Selecting "NASDAQ" shows the general market sentiment alongside the company-specific sentiment.
169
+ - **Visual insights**: Top-left graph shows average sentiment score and closing price for the selected company.
 
 
170
  """
171
 
172
+ # --- Input options ---
173
  companies = sorted(df['Company'].unique().tolist()) + ["NASDAQ"]
174
  years = sorted(df['Year'].dropna().unique().tolist())
175
 
176
+ # --- Build Gradio Blocks ---
177
  with gr.Blocks() as demo:
178
+ # Markdown in alto
179
  gr.Markdown("# Dynamic Sentiment Dashboard")
180
+ gr.Markdown(description_text)
181
 
182
+ # Input sotto il Markdown
183
  with gr.Row():
184
+ dropdown_companies = gr.Dropdown(
185
+ choices=companies,
186
+ value=None,
187
+ multiselect=True,
188
+ label="Select Companies"
189
+ )
 
 
 
 
 
 
190
 
191
+ radio_aggregation = gr.Radio(
192
+ choices=["Month", "Year"],
193
+ value="Month",
194
+ label="Aggregation Level"
195
+ )
196
 
197
+ dropdown_year = gr.Dropdown(
198
+ choices=["All"] + years,
199
+ value="All",
200
+ label="Select Year"
201
+ )
202
+
203
+ # Bottone submit
204
+ submit_btn = gr.Button("Submit")
205
+
206
+ # Output
207
+ data_table = gr.Dataframe(label="Sentiment Table", type="pandas")
208
+ sentiment_plot = gr.Plot(label="Sentiment Trend")
209
+
210
+
211
+ submit_btn.click(
212
+ fn=show_sentiment,
213
+ inputs=[dropdown_companies, radio_aggregation, dropdown_year],
214
+ outputs=[data_table, sentiment_plot]
215
+ )
216
 
217
+ demo.launch()