JayLacoma commited on
Commit
62c3274
·
verified ·
1 Parent(s): ecbd665

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -417,10 +417,10 @@ def create_gradio_interface():
417
  with gr.Column():
418
  radar_chart_output = gr.Plot(label="Top Stocks Comparison")
419
 
420
- # --- DOWNLOAD BUTTON MOVED HERE (at the bottom, inside the tab) ---
421
  download_btn = gr.Button("📥 Download Tables (.txt)", variant="secondary")
422
- download_file = gr.File(visible=False) # Hidden file output
423
-
424
  with gr.TabItem("Help & Information"):
425
  gr.Markdown("""
426
  ## How to Use This Tool
@@ -445,34 +445,35 @@ def create_gradio_interface():
445
  Financial data is provided by Yahoo Finance via the yfinance package.
446
  """)
447
 
448
- # State to store results
449
- scores_state = gr.State(pd.DataFrame())
450
- metrics_state = gr.State(pd.DataFrame())
451
 
452
  def analyze_wrapper(*args):
453
  scores_df, metrics_df, bar_fig, radar_fig = asyncio.run(analyze_tickers(*args))
454
- return scores_df, metrics_df, bar_fig, radar_fig, scores_df, metrics_df
 
 
455
 
456
- def download_wrapper(scores_df, metrics_df):
457
- if scores_df.empty:
458
  return None
459
- return download_tables(scores_df, metrics_df)
460
 
461
  analyze_btn.click(
462
  analyze_wrapper,
463
  inputs=[tickers_input, growth_weight, value_weight, risk_weight],
464
- outputs=[scores_output, metrics_output, bar_chart_output, radar_chart_output, scores_state, metrics_state]
465
  )
466
 
467
  download_btn.click(
468
  download_wrapper,
469
- inputs=[scores_state, metrics_state],
470
- outputs=download_file
471
  )
472
 
473
  return iface
474
 
475
-
476
  # Entry point
477
  if __name__ == "__main__":
478
  logger.info("Starting Stock Analyzer app")
 
417
  with gr.Column():
418
  radar_chart_output = gr.Plot(label="Top Stocks Comparison")
419
 
420
+ # --- Working Download Button + File Output ---
421
  download_btn = gr.Button("📥 Download Tables (.txt)", variant="secondary")
422
+ download_output = gr.File(label="Download") # This will be invisible until file is ready
423
+
424
  with gr.TabItem("Help & Information"):
425
  gr.Markdown("""
426
  ## How to Use This Tool
 
445
  Financial data is provided by Yahoo Finance via the yfinance package.
446
  """)
447
 
448
+ # We'll store the latest DataFrames in a simple way using a wrapper
449
+ last_scores = [pd.DataFrame()]
450
+ last_metrics = [pd.DataFrame()]
451
 
452
  def analyze_wrapper(*args):
453
  scores_df, metrics_df, bar_fig, radar_fig = asyncio.run(analyze_tickers(*args))
454
+ last_scores[0] = scores_df
455
+ last_metrics[0] = metrics_df
456
+ return scores_df, metrics_df, bar_fig, radar_fig
457
 
458
+ def download_wrapper():
459
+ if last_scores[0].empty:
460
  return None
461
+ return download_tables(last_scores[0], last_metrics[0])
462
 
463
  analyze_btn.click(
464
  analyze_wrapper,
465
  inputs=[tickers_input, growth_weight, value_weight, risk_weight],
466
+ outputs=[scores_output, metrics_output, bar_chart_output, radar_chart_output]
467
  )
468
 
469
  download_btn.click(
470
  download_wrapper,
471
+ inputs=[],
472
+ outputs=download_output
473
  )
474
 
475
  return iface
476
 
 
477
  # Entry point
478
  if __name__ == "__main__":
479
  logger.info("Starting Stock Analyzer app")