event handling minor fixes
Browse files- app.py +35 -20
- json/app_column_config.json +1 -0
app.py
CHANGED
@@ -310,11 +310,11 @@ if not last_result_df.empty:
|
|
310 |
selected_ticker = last_result_df.iloc[0][rename_columns.get('ticker','ticker')]
|
311 |
# Fetch initial company info
|
312 |
if selected_ticker:
|
313 |
-
|
|
|
314 |
else:
|
315 |
init_name, init_summary, init_details = "", "", pd.DataFrame()
|
316 |
|
317 |
-
|
318 |
# ---------------------------------------------------------------------------
|
319 |
# UI ------------------------------------------------------------------------
|
320 |
# ---------------------------------------------------------------------------
|
@@ -387,12 +387,15 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
387 |
company_chart_title = gr.Markdown("## Key Metrics Radar Chart")
|
388 |
company_plot = gr.Plot(visible=True)
|
389 |
|
390 |
-
def on_company_tab(
|
391 |
global selected_ticker
|
392 |
-
if evt.selected and selected_ticker:
|
|
|
393 |
maestro_details = maestro[company_details_cols].copy()
|
394 |
# maestro_details.drop(columns=["embeddings"], inplace=True, errors="ignore")
|
395 |
-
name, summary, details_df = utils.get_company_info(
|
|
|
|
|
396 |
|
397 |
# Create spider plot figure
|
398 |
fig = None
|
@@ -408,9 +411,12 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
408 |
gr.update(value=f"## {name}"),
|
409 |
gr.update(value=summary),
|
410 |
gr.update(value=details_df),
|
411 |
-
gr.update(value=fig)
|
|
|
|
|
412 |
)
|
413 |
-
|
|
|
414 |
|
415 |
company_tab.select(
|
416 |
on_company_tab,
|
@@ -418,11 +424,9 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
418 |
outputs=[company_title, company_summary, company_details, company_plot]
|
419 |
)
|
420 |
|
421 |
-
|
422 |
page_state = gr.State(1)
|
423 |
|
424 |
-
|
425 |
-
# ---------------------- COMPANY DETAIL ---------------------
|
426 |
def on_table_select(evt: gr.SelectData):
|
427 |
print(f"DEBUG on_table_select called: index={evt.index}, value={evt.value}")
|
428 |
global last_result_df, selected_ticker
|
@@ -439,9 +443,9 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
439 |
return filter_by_column(evt) + (
|
440 |
gr.update(selected=0), "", "", pd.DataFrame()
|
441 |
)
|
442 |
-
|
443 |
-
|
444 |
-
)
|
445 |
|
446 |
# Create spider plot figure
|
447 |
fig = None
|
@@ -458,8 +462,9 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
458 |
last_result_df,
|
459 |
pagination_label,
|
460 |
page_state,
|
461 |
-
summary_display,
|
462 |
-
gr.update(
|
|
|
463 |
gr.update(value=f"## {name}"),
|
464 |
gr.update(value=summary),
|
465 |
gr.update(value=details_df),
|
@@ -488,7 +493,8 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
488 |
# if it really changed, fetch new info
|
489 |
if new_ticker != selected_ticker:
|
490 |
selected_ticker = new_ticker
|
491 |
-
|
|
|
492 |
|
493 |
# Create spider plot figure
|
494 |
fig = None
|
@@ -502,12 +508,12 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
502 |
gr.update(value=f"## {name}"),
|
503 |
gr.update(value=summary),
|
504 |
gr.update(value=details_df),
|
505 |
-
gr.update(value=fig)
|
|
|
506 |
)
|
507 |
|
508 |
# otherwise leave components as‑is
|
509 |
return gr.update(), gr.update(), gr.update(), gr.update()
|
510 |
-
|
511 |
output_df.change(
|
512 |
on_df_first_row_change,
|
513 |
inputs=[output_df],
|
@@ -549,7 +555,11 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
549 |
search_all,
|
550 |
inputs=inputs,
|
551 |
outputs=[output_df, pagination_label, ticker_input, theme_input, summary_display]
|
552 |
-
)
|
|
|
|
|
|
|
|
|
553 |
|
554 |
ticker_input.submit(
|
555 |
reset_page, [], page_state
|
@@ -557,6 +567,10 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
557 |
search_all,
|
558 |
inputs=inputs,
|
559 |
outputs=[output_df, pagination_label, ticker_input, theme_input, summary_display]
|
|
|
|
|
|
|
|
|
560 |
)
|
561 |
|
562 |
theme_input.submit(
|
@@ -614,7 +628,8 @@ with gr.Blocks(title="Swift Stock Screener, by Reddgr") as front:
|
|
614 |
|
615 |
def on_tab_change(tab_index):
|
616 |
if tab_index == 1 and selected_ticker:
|
617 |
-
|
|
|
618 |
|
619 |
# Create spider plot figure
|
620 |
fig = None
|
|
|
310 |
selected_ticker = last_result_df.iloc[0][rename_columns.get('ticker','ticker')]
|
311 |
# Fetch initial company info
|
312 |
if selected_ticker:
|
313 |
+
maestro_details = maestro[company_details_cols].copy()
|
314 |
+
init_name, init_summary, init_details = utils.get_company_info(maestro_details, selected_ticker, rename_columns)
|
315 |
else:
|
316 |
init_name, init_summary, init_details = "", "", pd.DataFrame()
|
317 |
|
|
|
318 |
# ---------------------------------------------------------------------------
|
319 |
# UI ------------------------------------------------------------------------
|
320 |
# ---------------------------------------------------------------------------
|
|
|
387 |
company_chart_title = gr.Markdown("## Key Metrics Radar Chart")
|
388 |
company_plot = gr.Plot(visible=True)
|
389 |
|
390 |
+
def on_company_tab():
|
391 |
global selected_ticker
|
392 |
+
# if evt.selected and selected_ticker:
|
393 |
+
if selected_ticker:
|
394 |
maestro_details = maestro[company_details_cols].copy()
|
395 |
# maestro_details.drop(columns=["embeddings"], inplace=True, errors="ignore")
|
396 |
+
name, summary, details_df = utils.get_company_info(
|
397 |
+
maestro_details, selected_ticker, rename_columns
|
398 |
+
)
|
399 |
|
400 |
# Create spider plot figure
|
401 |
fig = None
|
|
|
411 |
gr.update(value=f"## {name}"),
|
412 |
gr.update(value=summary),
|
413 |
gr.update(value=details_df),
|
414 |
+
gr.update(value=fig),
|
415 |
+
# gr.update()
|
416 |
+
### summary_display ##########
|
417 |
)
|
418 |
+
# No company selected – leave widgets as‑is
|
419 |
+
return gr.update(), gr.update(), gr.update(), gr.update() # summary_display
|
420 |
|
421 |
company_tab.select(
|
422 |
on_company_tab,
|
|
|
424 |
outputs=[company_title, company_summary, company_details, company_plot]
|
425 |
)
|
426 |
|
427 |
+
# ---------------------- TABLE SELECT (CLICK) ---------------------
|
428 |
page_state = gr.State(1)
|
429 |
|
|
|
|
|
430 |
def on_table_select(evt: gr.SelectData):
|
431 |
print(f"DEBUG on_table_select called: index={evt.index}, value={evt.value}")
|
432 |
global last_result_df, selected_ticker
|
|
|
443 |
return filter_by_column(evt) + (
|
444 |
gr.update(selected=0), "", "", pd.DataFrame()
|
445 |
)
|
446 |
+
|
447 |
+
maestro_details = maestro[company_details_cols].copy()
|
448 |
+
name, summary, details_df = utils.get_company_info(maestro_details, ticker, rename_columns)
|
449 |
|
450 |
# Create spider plot figure
|
451 |
fig = None
|
|
|
462 |
last_result_df,
|
463 |
pagination_label,
|
464 |
page_state,
|
465 |
+
#summary_display,
|
466 |
+
gr.update(),
|
467 |
+
gr.update(selected=1),
|
468 |
gr.update(value=f"## {name}"),
|
469 |
gr.update(value=summary),
|
470 |
gr.update(value=details_df),
|
|
|
493 |
# if it really changed, fetch new info
|
494 |
if new_ticker != selected_ticker:
|
495 |
selected_ticker = new_ticker
|
496 |
+
maestro_details = maestro[company_details_cols].copy()
|
497 |
+
name, summary, details_df = utils.get_company_info(maestro_details, selected_ticker, rename_columns)
|
498 |
|
499 |
# Create spider plot figure
|
500 |
fig = None
|
|
|
508 |
gr.update(value=f"## {name}"),
|
509 |
gr.update(value=summary),
|
510 |
gr.update(value=details_df),
|
511 |
+
gr.update(value=fig),
|
512 |
+
# gr.update()
|
513 |
)
|
514 |
|
515 |
# otherwise leave components as‑is
|
516 |
return gr.update(), gr.update(), gr.update(), gr.update()
|
|
|
517 |
output_df.change(
|
518 |
on_df_first_row_change,
|
519 |
inputs=[output_df],
|
|
|
555 |
search_all,
|
556 |
inputs=inputs,
|
557 |
outputs=[output_df, pagination_label, ticker_input, theme_input, summary_display]
|
558 |
+
).then(
|
559 |
+
on_company_tab,
|
560 |
+
inputs=[],
|
561 |
+
outputs=[company_title, company_summary, company_details, company_plot]
|
562 |
+
)
|
563 |
|
564 |
ticker_input.submit(
|
565 |
reset_page, [], page_state
|
|
|
567 |
search_all,
|
568 |
inputs=inputs,
|
569 |
outputs=[output_df, pagination_label, ticker_input, theme_input, summary_display]
|
570 |
+
).then(
|
571 |
+
on_company_tab,
|
572 |
+
inputs=[],
|
573 |
+
outputs=[company_title, company_summary, company_details, company_plot]
|
574 |
)
|
575 |
|
576 |
theme_input.submit(
|
|
|
628 |
|
629 |
def on_tab_change(tab_index):
|
630 |
if tab_index == 1 and selected_ticker:
|
631 |
+
maestro_details = maestro[company_details_cols].copy()
|
632 |
+
name, summary, details_df = utils.get_company_info(maestro_details, selected_ticker, rename_columns)
|
633 |
|
634 |
# Create spider plot figure
|
635 |
fig = None
|
json/app_column_config.json
CHANGED
@@ -69,6 +69,7 @@
|
|
69 |
"fundFamily"
|
70 |
],
|
71 |
"company_details_cols": [
|
|
|
72 |
"ticker",
|
73 |
"security",
|
74 |
"country",
|
|
|
69 |
"fundFamily"
|
70 |
],
|
71 |
"company_details_cols": [
|
72 |
+
"longBusinessSummary",
|
73 |
"ticker",
|
74 |
"security",
|
75 |
"country",
|