with open('app.py', 'r') as f:
content = f.read()
start_idx = content.find("def update_dashboard_wrapper(")
end_idx = content.find("inputs_list = [benchmark_cb")
new_wrapper = """def update_dashboard_wrapper(tickers, time_range, model_keys, tiingo_key, av_key):
res = load_dashboard(tickers, time_range, model_keys, tiingo_key, av_key)
# res has 17 items: fcst_df, fcst_fig, 6 figs, 6 descs, err, stat, obs
stat_html = f"
{res[15]}
"
return tuple(list(res[:15]) + [stat_html, res[16]])
def perform_bootstrap(tickers, time_range, model_keys, tiingo, av):
api_keys = {"tiingo": tiingo, "alphavantage": av}
success, msg = bootstrap_historical_data(api_keys)
if not success:
import pandas as pd
return [pd.DataFrame(), empty_fig(msg)] + [empty_fig(msg)]*6 + [""]*6 + [msg, f"{msg}
", ""]
return update_dashboard_wrapper(tickers, time_range, model_keys, tiingo, av)
"""
content = content[:start_idx] + new_wrapper + content[end_idx:]
# Also fix outputs_list which might be broken
start_idx_out = content.find("outputs_list = [")
end_idx_out = content.find("demo.load(", start_idx_out)
new_outputs = """outputs_list = [
forecast_table, forecast_chart,
chart_10k, chart_price, chart_roll_ret, chart_vol, chart_dd, chart_corr,
desc_10k, desc_price, desc_roll, desc_err, desc_dd, desc_regime,
error_md, status_md, obs_md
]
"""
content = content[:start_idx_out] + new_outputs + content[end_idx_out:]
with open('app.py', 'w') as f:
f.write(content)