Update app.py
Browse files
app.py
CHANGED
|
@@ -13,9 +13,8 @@ MODEL_PRICE_MICROSOFT = "SelmaNajih001/PricePredictionForMicrosoft"
|
|
| 13 |
MODEL_FINBERT = "ProsusAI/finbert"
|
| 14 |
|
| 15 |
TICKERS = {
|
| 16 |
-
"Tesla": "TSLA",
|
| 17 |
-
"Microsoft": "MSFT"
|
| 18 |
-
"Nvidia": "NVDA"
|
| 19 |
}
|
| 20 |
companies = list(TICKERS.keys())
|
| 21 |
|
|
@@ -123,11 +122,11 @@ for company in companies:
|
|
| 123 |
# --- FUNZIONE PER GRADIO ---
|
| 124 |
def show_company_data(selected_companies, aggregation="Day"):
|
| 125 |
if not selected_companies:
|
| 126 |
-
return "
|
| 127 |
|
| 128 |
agg_col = {"Day": "Day", "Month": "Month", "Year": "Year"}.get(aggregation, "Day")
|
| 129 |
|
| 130 |
-
# ---
|
| 131 |
fig_strat = go.Figure()
|
| 132 |
for c in selected_companies:
|
| 133 |
if c not in dfs_final:
|
|
@@ -135,25 +134,34 @@ def show_company_data(selected_companies, aggregation="Day"):
|
|
| 135 |
df_c = dfs_final[c]
|
| 136 |
|
| 137 |
df_grouped = df_c.groupby(agg_col).agg({
|
| 138 |
-
'StrategyA_Cumulative':'last',
|
| 139 |
-
'StrategyB_Cumulative':'last',
|
| 140 |
-
'StrategyC_Cumulative':'last'
|
| 141 |
}).reset_index()
|
| 142 |
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
fig_strat.add_trace(go.Scatter(
|
| 145 |
-
x=df_grouped[agg_col],
|
| 146 |
-
|
|
|
|
|
|
|
| 147 |
))
|
| 148 |
|
| 149 |
fig_strat.update_layout(
|
| 150 |
-
title="
|
| 151 |
xaxis_title=aggregation,
|
| 152 |
-
yaxis_title="Cumulative",
|
| 153 |
template="plotly_dark",
|
| 154 |
hovermode="x unified"
|
| 155 |
)
|
| 156 |
|
|
|
|
| 157 |
# --- Grafico Prezzi ---
|
| 158 |
fig_price = go.Figure()
|
| 159 |
for c in selected_companies:
|
|
|
|
| 13 |
MODEL_FINBERT = "ProsusAI/finbert"
|
| 14 |
|
| 15 |
TICKERS = {
|
| 16 |
+
"Tesla Inc": "TSLA",
|
| 17 |
+
"Microsoft": "MSFT"
|
|
|
|
| 18 |
}
|
| 19 |
companies = list(TICKERS.keys())
|
| 20 |
|
|
|
|
| 122 |
# --- FUNZIONE PER GRADIO ---
|
| 123 |
def show_company_data(selected_companies, aggregation="Day"):
|
| 124 |
if not selected_companies:
|
| 125 |
+
return "Please select at least one company", None, None
|
| 126 |
|
| 127 |
agg_col = {"Day": "Day", "Month": "Month", "Year": "Year"}.get(aggregation, "Day")
|
| 128 |
|
| 129 |
+
# --- Strategies Chart ---
|
| 130 |
fig_strat = go.Figure()
|
| 131 |
for c in selected_companies:
|
| 132 |
if c not in dfs_final:
|
|
|
|
| 134 |
df_c = dfs_final[c]
|
| 135 |
|
| 136 |
df_grouped = df_c.groupby(agg_col).agg({
|
| 137 |
+
'StrategyA_Cumulative': 'last',
|
| 138 |
+
'StrategyB_Cumulative': 'last',
|
| 139 |
+
'StrategyC_Cumulative': 'last'
|
| 140 |
}).reset_index()
|
| 141 |
|
| 142 |
+
strategy_labels = {
|
| 143 |
+
'StrategyA_Cumulative': "Custom Sentiment",
|
| 144 |
+
'StrategyB_Cumulative': "Regression",
|
| 145 |
+
'StrategyC_Cumulative': "FinBERT"
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
for strat in ['StrategyA_Cumulative', 'StrategyB_Cumulative', 'StrategyC_Cumulative']:
|
| 149 |
fig_strat.add_trace(go.Scatter(
|
| 150 |
+
x=df_grouped[agg_col],
|
| 151 |
+
y=df_grouped[strat],
|
| 152 |
+
mode="lines",
|
| 153 |
+
name=f"{c} - {strategy_labels[strat]}"
|
| 154 |
))
|
| 155 |
|
| 156 |
fig_strat.update_layout(
|
| 157 |
+
title="Strategies Comparison (Custom Sentiment, Regression, FinBERT)",
|
| 158 |
xaxis_title=aggregation,
|
| 159 |
+
yaxis_title="Cumulative Value",
|
| 160 |
template="plotly_dark",
|
| 161 |
hovermode="x unified"
|
| 162 |
)
|
| 163 |
|
| 164 |
+
|
| 165 |
# --- Grafico Prezzi ---
|
| 166 |
fig_price = go.Figure()
|
| 167 |
for c in selected_companies:
|