Update app.py
Browse files
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 |
-
# ---
|
| 421 |
download_btn = gr.Button("📥 Download Tables (.txt)", variant="secondary")
|
| 422 |
-
|
| 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 |
-
#
|
| 449 |
-
|
| 450 |
-
|
| 451 |
|
| 452 |
def analyze_wrapper(*args):
|
| 453 |
scores_df, metrics_df, bar_fig, radar_fig = asyncio.run(analyze_tickers(*args))
|
| 454 |
-
|
|
|
|
|
|
|
| 455 |
|
| 456 |
-
def download_wrapper(
|
| 457 |
-
if
|
| 458 |
return None
|
| 459 |
-
return download_tables(
|
| 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
|
| 465 |
)
|
| 466 |
|
| 467 |
download_btn.click(
|
| 468 |
download_wrapper,
|
| 469 |
-
inputs=[
|
| 470 |
-
outputs=
|
| 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")
|