Cosmographer commited on
Commit
62732f5
·
verified ·
1 Parent(s): 8d3ce78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -1720,18 +1720,30 @@ with gr.Blocks(css=css, title="DataSynth — Analytics Hub") as demo:
1720
  outputs=[prep_output, clean_state]
1721
  )
1722
 
1723
- # Column selection helpers
1724
- def _select_all_cols(df_path):
1725
- if not df_path:
1726
- return gr.CheckboxGroup.update(choices=[])
1727
- df = pd.read_csv(df_path)
1728
- return gr.CheckboxGroup.update(value=df.columns.tolist())
 
 
 
 
 
 
 
 
 
1729
 
1730
- def _deselect_all_cols():
1731
- return gr.CheckboxGroup.update(value=[])
 
 
 
1732
 
1733
- select_all_cols.click(fn=_select_all_cols, inputs=[df_state], outputs=[available_cols])
1734
- deselect_all_cols.click(fn=_deselect_all_cols, outputs=[available_cols])
1735
 
1736
  # Show/hide custom value inputs based on method selection
1737
  def _toggle_custom_inputs(num_method, cat_method):
 
1720
  outputs=[prep_output, clean_state]
1721
  )
1722
 
1723
+ # safe helper: read columns from persisted df path
1724
+ def _cols_from_df_path(df_path):
1725
+ try:
1726
+ if not df_path:
1727
+ return []
1728
+ df = pd.read_csv(df_path)
1729
+ return [str(c) for c in df.columns]
1730
+ except Exception:
1731
+ return []
1732
+
1733
+ # callback for Select All button
1734
+ def select_all_cols(df_path):
1735
+ cols = _cols_from_df_path(df_path)
1736
+ # return gr.update(...) (NOT component.update). Set both choices and value.
1737
+ return gr.update(choices=cols, value=cols)
1738
 
1739
+ # callback for Deselect All button
1740
+ def deselect_all_cols(df_path):
1741
+ cols = _cols_from_df_path(df_path)
1742
+ # keep choices, but clear value to deselect all
1743
+ return gr.update(choices=cols, value=[])
1744
 
1745
+ select_all_cols.click(fn=select_all_cols, inputs=[df_state], outputs=[available_cols])
1746
+ deselect_all_cols.click(fn=deselect_all_cols, inputs=[df_state], outputs=[available_cols])
1747
 
1748
  # Show/hide custom value inputs based on method selection
1749
  def _toggle_custom_inputs(num_method, cat_method):