Tulitula commited on
Commit
b88f474
·
verified ·
1 Parent(s): 0dfa99d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -18
app.py CHANGED
@@ -615,25 +615,28 @@ with gr.Blocks(title="Efficient Portfolio Advisor") as demo:
615
  run_btn = gr.Button("Compute (build dataset & suggest)")
616
  # -----------------------------------------------------
617
 
618
- gr.Markdown("### Suggestions")
 
619
  with gr.Row():
620
- btn_low = gr.Button("Show Low")
621
- btn_med = gr.Button("Show Medium")
622
- btn_high = gr.Button("Show High")
623
- low_txt = gr.Markdown()
624
- med_txt = gr.Markdown()
625
- high_txt = gr.Markdown()
626
 
627
  with gr.Column(scale=1):
628
- plot = gr.Image(label="Capital Market Line (CAPM)", type="pil")
629
- summary = gr.Markdown(label="Inputs & Results")
 
630
  positions = gr.Dataframe(
631
  label="Computed positions",
632
  headers=["ticker", "amount_usd", "weight_exposure", "beta"],
633
  datatype=["str", "number", "number", "number"],
634
  col_count=(4, "fixed"),
635
  value=empty_positions_df(),
636
- interactive=False
 
637
  )
638
  sugg_table = gr.Dataframe(
639
  label="Selected suggestion holdings (% / $)",
@@ -641,20 +644,19 @@ with gr.Blocks(title="Efficient Portfolio Advisor") as demo:
641
  datatype=["str", "number", "number"],
642
  col_count=(3, "fixed"),
643
  value=empty_suggestion_df(),
644
- interactive=False
 
645
  )
646
- dl = gr.File(label="Generated dataset CSV", value=None, visible=True)
647
 
648
- # wire search / add / locking
649
  search_btn.click(fn=search_tickers_cb, inputs=q, outputs=[search_note, matches])
650
  add_btn.click(fn=add_symbol, inputs=[matches, table], outputs=[table, search_note])
651
  table.change(fn=lock_ticker_column, inputs=table, outputs=table)
652
-
653
- # horizon updates globals silently (no UI output)
654
  horizon.change(fn=set_horizon, inputs=horizon, outputs=[])
655
 
656
- # compute + render (default to Medium band)
657
- run_btn.click(
658
  fn=compute,
659
  inputs=[lookback, table, gr.State("Medium")],
660
  outputs=[
@@ -665,7 +667,19 @@ with gr.Blocks(title="Efficient Portfolio Advisor") as demo:
665
  ]
666
  )
667
 
668
- # band buttons recompute picks quickly
 
 
 
 
 
 
 
 
 
 
 
 
669
  btn_low.click(
670
  fn=compute,
671
  inputs=[lookback, table, gr.State("Low")],
 
615
  run_btn = gr.Button("Compute (build dataset & suggest)")
616
  # -----------------------------------------------------
617
 
618
+ # Suggestions UI (hidden until Compute)
619
+ sugg_hdr = gr.Markdown("### Suggestions", visible=False)
620
  with gr.Row():
621
+ btn_low = gr.Button("Show Low", visible=False)
622
+ btn_med = gr.Button("Show Medium", visible=False)
623
+ btn_high = gr.Button("Show High", visible=False)
624
+ low_txt = gr.Markdown(visible=False)
625
+ med_txt = gr.Markown(visible=False) if hasattr(gr, "Markown") else gr.Markdown(visible=False)
626
+ high_txt = gr.Markdown(visible=False)
627
 
628
  with gr.Column(scale=1):
629
+ # Results (hidden until Compute)
630
+ plot = gr.Image(label="Capital Market Line (CAPM)", type="pil", visible=False)
631
+ summary = gr.Markdown(label="Inputs & Results", visible=False)
632
  positions = gr.Dataframe(
633
  label="Computed positions",
634
  headers=["ticker", "amount_usd", "weight_exposure", "beta"],
635
  datatype=["str", "number", "number", "number"],
636
  col_count=(4, "fixed"),
637
  value=empty_positions_df(),
638
+ interactive=False,
639
+ visible=False
640
  )
641
  sugg_table = gr.Dataframe(
642
  label="Selected suggestion holdings (% / $)",
 
644
  datatype=["str", "number", "number"],
645
  col_count=(3, "fixed"),
646
  value=empty_suggestion_df(),
647
+ interactive=False,
648
+ visible=False
649
  )
650
+ dl = gr.File(label="Generated dataset CSV", value=None, visible=False)
651
 
652
+ # --- wiring ---
653
  search_btn.click(fn=search_tickers_cb, inputs=q, outputs=[search_note, matches])
654
  add_btn.click(fn=add_symbol, inputs=[matches, table], outputs=[table, search_note])
655
  table.change(fn=lock_ticker_column, inputs=table, outputs=table)
 
 
656
  horizon.change(fn=set_horizon, inputs=horizon, outputs=[])
657
 
658
+ # Compute (default to Medium band)
659
+ compute_evt = run_btn.click(
660
  fn=compute,
661
  inputs=[lookback, table, gr.State("Medium")],
662
  outputs=[
 
667
  ]
668
  )
669
 
670
+ # After compute finishes, reveal all results + Suggestions UI
671
+ def _reveal():
672
+ up = gr.update(visible=True)
673
+ return (up, up, up, up, up, up, up, up, up, up, up, up)
674
+
675
+ compute_evt.then(
676
+ _reveal,
677
+ inputs=[],
678
+ outputs=[plot, summary, positions, sugg_table, dl,
679
+ sugg_hdr, btn_low, btn_med, btn_high, low_txt, med_txt, high_txt]
680
+ )
681
+
682
+ # Band buttons (work once they’re revealed)
683
  btn_low.click(
684
  fn=compute,
685
  inputs=[lookback, table, gr.State("Low")],