Spaces:
Running
Running
Update app.py
Browse files
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 |
-
###
|
| 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
|
| 163 |
-
- **Dataset structure**: The dataset includes a company column
|
| 164 |
-
- **Sentiment aggregation**:
|
| 165 |
- **NASDAQ comparison**: Selecting "NASDAQ" shows the general market sentiment alongside the company-specific sentiment.
|
| 166 |
-
- **Visual insights**:
|
| 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 |
-
#
|
| 172 |
companies = sorted(df['Company'].unique().tolist()) + ["NASDAQ"]
|
| 173 |
years = sorted(df['Year'].dropna().unique().tolist())
|
| 174 |
|
| 175 |
-
#
|
| 176 |
with gr.Blocks() as demo:
|
|
|
|
| 177 |
gr.Markdown("# Dynamic Sentiment Dashboard")
|
|
|
|
| 178 |
|
|
|
|
| 179 |
with gr.Row():
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 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 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
-
|
| 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()
|
|
|
|
|
|
|
|
|