Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
companies = sorted(df['Company'].unique().tolist()) + ["NASDAQ"]
|
| 156 |
years = sorted(df['Year'].dropna().unique().tolist())
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+

|
| 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")
|