Update scripts/app.py
Browse files- scripts/app.py +36 -52
scripts/app.py
CHANGED
|
@@ -528,75 +528,59 @@ def get_recent_transactions():
|
|
| 528 |
|
| 529 |
custom_css = """
|
| 530 |
.metric-box { background-color: #1f2937; padding: 20px; border-radius: 12px; border: 1px solid #374151; text-align: center; }
|
| 531 |
-
.metric-label { font-size: 1.1em; color: #9ca3af;
|
| 532 |
.metric-value { font-size: 2.2em; font-weight: 700; color: #e5e7eb; }
|
| 533 |
-
.disclaimer-box { background-color: #374151; padding: 15px; border-radius: 8px; border-left: 4px solid #f59e0b; color: #d1d5db; font-size: 0.9em; margin-bottom: 20px; }
|
| 534 |
"""
|
| 535 |
|
| 536 |
-
with gr.Blocks(css=custom_css, title="Deep RL
|
| 537 |
-
# JS to force dark mode
|
| 538 |
gr.HTML("""<script>function forceDark(){document.body.classList.add('dark');} forceDark(); setTimeout(forceDark, 500);</script>""")
|
| 539 |
-
|
| 540 |
gr.Markdown("# ๐ง Deep RL & LLM Portfolio Manager")
|
| 541 |
|
| 542 |
with gr.Tabs():
|
| 543 |
-
with gr.TabItem("๐
|
| 544 |
-
|
| 545 |
with gr.Row():
|
| 546 |
-
gr.HTML(f"<div class='metric-box'><div class='metric-label'>
|
| 547 |
-
gr.HTML(f"<div class='metric-box'><div class='metric-label'>24h Change</div><div class='metric-value'
|
| 548 |
with gr.Row():
|
| 549 |
-
with gr.Column(scale=3):
|
| 550 |
with gr.Row():
|
| 551 |
-
with gr.Column(scale=1):
|
| 552 |
-
with gr.Column(scale=2):
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
gr.Markdown("### Generate Tomorrow's Strategy")
|
| 558 |
-
run_btn = gr.Button("๐ Run Overnight Analysis", variant="primary", size="lg")
|
| 559 |
-
status_output = gr.Textbox(label="System Status", interactive=False, lines=1)
|
| 560 |
-
gr.Markdown("---")
|
| 561 |
with gr.Row():
|
| 562 |
with gr.Column(scale=2):
|
| 563 |
-
gr.
|
| 564 |
-
|
| 565 |
-
gr.Markdown("### ๐ง XAI Feature Importance")
|
| 566 |
-
xai_output_plot = gr.Plot(label="Influential Factors", show_label=False)
|
| 567 |
with gr.Column(scale=3):
|
| 568 |
-
|
| 569 |
-
run_btn.click(
|
| 570 |
|
| 571 |
-
with gr.TabItem("๐
|
| 572 |
-
gr.Markdown("### Analyze Past Market Performance")
|
| 573 |
with gr.Row():
|
| 574 |
with gr.Column(scale=1):
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
with gr.TabItem("๐ Historical Simulation"):
|
| 587 |
-
gr.Markdown("### Backtest Strategy")
|
| 588 |
-
gr.HTML(f"<div class='disclaimer-box'>โ ๏ธ Model trained on {TRAIN_START_DATE} to {TRAIN_END_DATE}. Outside usage may be inaccurate.</div>")
|
| 589 |
with gr.Row():
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
sim_metrics_df = gr.Dataframe(interactive=False, wrap=True, label="Professional Metrics")
|
| 599 |
-
sim_btn.click(fn=run_historical_simulation, inputs=[start_date_input, end_date_input], outputs=[sim_plot, sim_status, sim_metrics_df])
|
| 600 |
|
| 601 |
if __name__ == "__main__":
|
| 602 |
demo.queue().launch(server_name="0.0.0.0", server_port=7860, debug=True, share=True)
|
|
|
|
| 528 |
|
| 529 |
custom_css = """
|
| 530 |
.metric-box { background-color: #1f2937; padding: 20px; border-radius: 12px; border: 1px solid #374151; text-align: center; }
|
| 531 |
+
.metric-label { font-size: 1.1em; color: #9ca3af; }
|
| 532 |
.metric-value { font-size: 2.2em; font-weight: 700; color: #e5e7eb; }
|
|
|
|
| 533 |
"""
|
| 534 |
|
| 535 |
+
with gr.Blocks(css=custom_css, title="Deep RL Manager") as demo:
|
|
|
|
| 536 |
gr.HTML("""<script>function forceDark(){document.body.classList.add('dark');} forceDark(); setTimeout(forceDark, 500);</script>""")
|
|
|
|
| 537 |
gr.Markdown("# ๐ง Deep RL & LLM Portfolio Manager")
|
| 538 |
|
| 539 |
with gr.Tabs():
|
| 540 |
+
with gr.TabItem("๐ Dashboard"):
|
| 541 |
+
nw, chg = get_dash_metrics()
|
| 542 |
with gr.Row():
|
| 543 |
+
gr.HTML(f"<div class='metric-box'><div class='metric-label'>Simulated Net Worth</div><div class='metric-value'>{nw}</div></div>")
|
| 544 |
+
gr.HTML(f"<div class='metric-box'><div class='metric-label'>24h Change</div><div class='metric-value'>{chg}</div></div>")
|
| 545 |
with gr.Row():
|
| 546 |
+
with gr.Column(scale=3): gr.Plot(value=get_hist_plot(), label="History")
|
| 547 |
with gr.Row():
|
| 548 |
+
with gr.Column(scale=1): gr.Plot(value=get_current_allocation_plot(), label="Allocation")
|
| 549 |
+
with gr.Column(scale=2): gr.Dataframe(value=get_trans(), label="Transactions")
|
| 550 |
+
|
| 551 |
+
with gr.TabItem("๐ฎ Forecast"):
|
| 552 |
+
run_btn = gr.Button("๐ Run Analysis", variant="primary")
|
| 553 |
+
stat = gr.Textbox(label="Status", lines=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 554 |
with gr.Row():
|
| 555 |
with gr.Column(scale=2):
|
| 556 |
+
alloc_out = gr.Dataframe(headers=["Asset", "Allocation"])
|
| 557 |
+
xai_out = gr.Plot(label="XAI Factors")
|
|
|
|
|
|
|
| 558 |
with gr.Column(scale=3):
|
| 559 |
+
ai_out = gr.HTML(label="Report")
|
| 560 |
+
run_btn.click(predict_and_analyze, None, [stat, alloc_out, xai_out, ai_out])
|
| 561 |
|
| 562 |
+
with gr.TabItem("๐
Analyst"):
|
|
|
|
| 563 |
with gr.Row():
|
| 564 |
with gr.Column(scale=1):
|
| 565 |
+
ticks = ASSETS + FRED_IDS.values() if DASHBOARD_DATA_DF is None else [c for c in ASSETS + list(FRED_IDS.values()) if c in DASHBOARD_DATA_DF.columns]
|
| 566 |
+
sel = gr.Dropdown(choices=ticks, multiselect=True, label="Assets")
|
| 567 |
+
per = gr.Dropdown(choices=list(TIME_PERIODS.keys()), value="1 Year", label="Period")
|
| 568 |
+
btn = gr.Button("Analyze", variant="primary")
|
| 569 |
+
with gr.Column(scale=3): plot = gr.Plot()
|
| 570 |
+
rep = gr.Markdown()
|
| 571 |
+
btn.click(run_historical_analysis, [sel, per], [plot, rep])
|
| 572 |
+
|
| 573 |
+
with gr.TabItem("๐ Simulation"):
|
| 574 |
+
gr.Markdown("### Backtest")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
with gr.Row():
|
| 576 |
+
s_date = gr.Textbox(label="Start", value=(datetime.now()-timedelta(days=365)).strftime('%Y-%m-%d'))
|
| 577 |
+
e_date = gr.Textbox(label="End", value=(datetime.now()-timedelta(days=1)).strftime('%Y-%m-%d'))
|
| 578 |
+
s_btn = gr.Button("Run", variant="primary")
|
| 579 |
+
s_stat = gr.Textbox(label="Status")
|
| 580 |
+
s_plot = gr.Plot()
|
| 581 |
+
# FIX: Using Dataframe instead of Markdown for metrics table
|
| 582 |
+
s_metrics = gr.Dataframe(label="Professional Metrics")
|
| 583 |
+
s_btn.click(run_historical_simulation, [s_date, e_date], [s_plot, s_stat, s_metrics])
|
|
|
|
|
|
|
| 584 |
|
| 585 |
if __name__ == "__main__":
|
| 586 |
demo.queue().launch(server_name="0.0.0.0", server_port=7860, debug=True, share=True)
|