Update app.py
Browse files
app.py
CHANGED
|
@@ -335,6 +335,16 @@ async def analyze_tickers(
|
|
| 335 |
logger.info(f"Analysis completed in {time.time() - start_time:.2f} seconds")
|
| 336 |
return scores_table, metrics_table, bar_chart, radar_chart
|
| 337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
# Custom CSS for better appearance
|
| 339 |
custom_css = """
|
| 340 |
.gradio-container {
|
|
@@ -388,6 +398,10 @@ def create_gradio_interface():
|
|
| 388 |
bar_chart_output = gr.Plot(label="Component Scores Chart")
|
| 389 |
with gr.Column():
|
| 390 |
radar_chart_output = gr.Plot(label="Top Stocks Comparison")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
with gr.TabItem("Help & Information"):
|
| 393 |
gr.Markdown("""
|
|
@@ -414,12 +428,15 @@ def create_gradio_interface():
|
|
| 414 |
""")
|
| 415 |
|
| 416 |
def analyze_wrapper(*args):
|
| 417 |
-
|
|
|
|
|
|
|
|
|
|
| 418 |
|
| 419 |
analyze_btn.click(
|
| 420 |
analyze_wrapper,
|
| 421 |
inputs=[tickers_input, growth_weight, value_weight, risk_weight],
|
| 422 |
-
outputs=[scores_output, metrics_output, bar_chart_output, radar_chart_output]
|
| 423 |
)
|
| 424 |
|
| 425 |
return iface
|
|
|
|
| 335 |
logger.info(f"Analysis completed in {time.time() - start_time:.2f} seconds")
|
| 336 |
return scores_table, metrics_table, bar_chart, radar_chart
|
| 337 |
|
| 338 |
+
# Helper: Convert DataFrame to Markdown (for LLMs)
|
| 339 |
+
def dataframe_to_markdown(df: pd.DataFrame) -> str:
|
| 340 |
+
if df.empty:
|
| 341 |
+
return ""
|
| 342 |
+
df = df.fillna("N/A")
|
| 343 |
+
header = "| " + " | ".join(str(col) for col in df.columns) + " |"
|
| 344 |
+
separator = "| " + " | ".join(["---"] * len(df.columns)) + " |"
|
| 345 |
+
rows = ["| " + " | ".join(str(val) for val in row) + " |" for _, row in df.iterrows()]
|
| 346 |
+
return "\n".join([header, separator] + rows)
|
| 347 |
+
|
| 348 |
# Custom CSS for better appearance
|
| 349 |
custom_css = """
|
| 350 |
.gradio-container {
|
|
|
|
| 398 |
bar_chart_output = gr.Plot(label="Component Scores Chart")
|
| 399 |
with gr.Column():
|
| 400 |
radar_chart_output = gr.Plot(label="Top Stocks Comparison")
|
| 401 |
+
|
| 402 |
+
# --- NEW: Compact Markdown copy boxes (only appear after analysis) ---
|
| 403 |
+
scores_md = gr.Textbox(label="📋 Copy Scores as Markdown", value="", lines=3, max_lines=10, interactive=False)
|
| 404 |
+
metrics_md = gr.Textbox(label="📋 Copy Metrics as Markdown", value="", lines=3, max_lines=10, interactive=False)
|
| 405 |
|
| 406 |
with gr.TabItem("Help & Information"):
|
| 407 |
gr.Markdown("""
|
|
|
|
| 428 |
""")
|
| 429 |
|
| 430 |
def analyze_wrapper(*args):
|
| 431 |
+
scores_df, metrics_df, bar_fig, radar_fig = asyncio.run(analyze_tickers(*args))
|
| 432 |
+
scores_md_str = dataframe_to_markdown(scores_df)
|
| 433 |
+
metrics_md_str = dataframe_to_markdown(metrics_df)
|
| 434 |
+
return scores_df, metrics_df, bar_fig, radar_fig, scores_md_str, metrics_md_str
|
| 435 |
|
| 436 |
analyze_btn.click(
|
| 437 |
analyze_wrapper,
|
| 438 |
inputs=[tickers_input, growth_weight, value_weight, risk_weight],
|
| 439 |
+
outputs=[scores_output, metrics_output, bar_chart_output, radar_chart_output, scores_md, metrics_md]
|
| 440 |
)
|
| 441 |
|
| 442 |
return iface
|