SelmaNajih001 commited on
Commit
373edff
·
verified ·
1 Parent(s): cc8251a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -30
app.py CHANGED
@@ -151,39 +151,60 @@ def show_sentiment(selected_companies=None, aggregation="Day", selected_year="Al
151
 
152
  return df_grouped.tail(30), fig
153
 
154
- # --- GRADIO INTERFACE ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  companies = sorted(df['Company'].unique().tolist()) + ["NASDAQ"]
156
  years = sorted(df['Year'].dropna().unique().tolist())
157
 
158
- demo = gr.Interface(
159
- fn=show_sentiment,
160
- inputs=[
161
- gr.Dropdown(
162
- choices=companies,
163
- value=None,
164
- label="Select Companies (NASDAQ compares with general sentiment)",
165
- multiselect=False
166
- ),
167
- gr.Radio(
168
- choices=["Month", "Year"],
169
- value="Month",
170
- label="Aggregation Level"
171
- ),
172
- gr.Dropdown(
173
- choices=["All"] + years,
174
- value=2022,
175
- label="Select Year"
176
- )
177
- ],
178
- outputs=[
179
- gr.Dataframe(label="Sentiment Table", type="pandas"),
180
- gr.Plot(label="Sentiment Trend"),
181
- ],
182
- title="Dynamic Sentiment Dashboard",
183
- description="Shows sentiment scores aggregated by month or year. NASDAQ compares with general sentiment if selected."
184
 
185
-
186
- )
 
 
 
187
 
188
- demo.launch()
 
 
 
 
189
 
 
 
 
 
151
 
152
  return df_grouped.tail(30), fig
153
 
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
+ #### Example Graph
170
+
171
+ ![Example graph](https://upload.wikimedia.org/wikipedia/commons/4/45/Plot_example.png)
172
+ """
173
+
174
+ # Lista di aziende e anni
175
  companies = sorted(df['Company'].unique().tolist()) + ["NASDAQ"]
176
  years = sorted(df['Year'].dropna().unique().tolist())
177
 
178
+ # Interfaccia a colonne
179
+ with gr.Blocks() as demo:
180
+ gr.Markdown("# Dynamic Sentiment Dashboard")
181
+
182
+ with gr.Row():
183
+ # Colonna a sinistra: Markdown
184
+ with gr.Column(scale=1):
185
+ gr.Markdown(description_text)
186
+
187
+ # Colonna a destra: Input
188
+ with gr.Column(scale=2):
189
+ dropdown_companies = gr.Dropdown(
190
+ choices=companies,
191
+ value=None,
192
+ label="Select Companies (NASDAQ compares with general sentiment)",
193
+ multiselect=False
194
+ )
 
 
 
 
 
 
 
 
 
195
 
196
+ radio_aggregation = gr.Radio(
197
+ choices=["Month", "Year"],
198
+ value="Month",
199
+ label="Aggregation Level"
200
+ )
201
 
202
+ dropdown_year = gr.Dropdown(
203
+ choices=["All"] + years,
204
+ value=2022,
205
+ label="Select Year"
206
+ )
207
 
208
+ # Output sotto le colonne
209
+ gr.Dataframe(label="Sentiment Table", type="pandas")
210
+ gr.Plot(label="Sentiment Trend")