chrissoria commited on
Commit
9051895
·
1 Parent(s): 8a69599

Fix auto-extract chunk logic and add mutual exclusivity to task buttons

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -817,8 +817,12 @@ def run_auto_extract(input_type, spreadsheet_file, spreadsheet_column,
817
  divisions = min(3, max(1, num_items // 5))
818
  categories_per_chunk = 12
819
  else:
820
- divisions = min(5, max(1, num_items // 3))
821
- categories_per_chunk = 10
 
 
 
 
822
 
823
  # Extract categories
824
  extract_kwargs = {
@@ -1168,6 +1172,8 @@ def reset_all():
1168
  None, # image_folder
1169
  "", # image_description
1170
  None, # task_mode
 
 
1171
  ]
1172
  # Reset category inputs
1173
  for i in range(MAX_CATEGORIES):
@@ -1670,22 +1676,32 @@ Soria, C. (2025). CatLLM: A Python package for LLM-based text classification. DO
1670
 
1671
  # Manual entry button handler
1672
  def select_manual():
1673
- return ("manual",) + update_task_visibility("manual")
 
 
 
 
 
1674
 
1675
  manual_btn.click(
1676
  fn=select_manual,
1677
  inputs=[],
1678
- outputs=[task_mode, auto_extract_group, categories_group, model_group, run_btn, classify_output_group, status]
1679
  )
1680
 
1681
  # Auto-extract button handler
1682
  def select_auto_extract():
1683
- return ("auto_extract",) + update_task_visibility("auto_extract")
 
 
 
 
 
1684
 
1685
  auto_extract_btn.click(
1686
  fn=select_auto_extract,
1687
  inputs=[],
1688
- outputs=[task_mode, auto_extract_group, categories_group, model_group, run_btn, classify_output_group, status]
1689
  )
1690
 
1691
  # Run auto-extract button - extracts categories then shows next steps
@@ -1762,7 +1778,7 @@ Soria, C. (2025). CatLLM: A Python package for LLM-based text classification. DO
1762
  spreadsheet_file, spreadsheet_column,
1763
  pdf_upload_type, pdf_file, pdf_folder, pdf_description, pdf_mode,
1764
  image_upload_type, image_file, image_folder, image_description,
1765
- task_mode
1766
  ] + category_inputs + [
1767
  add_category_btn, category_count,
1768
  auto_extract_group, max_categories, auto_extract_status,
 
817
  divisions = min(3, max(1, num_items // 5))
818
  categories_per_chunk = 12
819
  else:
820
+ # Ensure each chunk has enough items for extraction
821
+ # We need at least categories_per_chunk items per chunk
822
+ divisions = max(1, num_items // 15) # Aim for ~15 items per chunk
823
+ divisions = min(divisions, 5) # Cap at 5 divisions
824
+ chunk_size = num_items // max(1, divisions)
825
+ categories_per_chunk = min(10, chunk_size - 1) # Leave room for extraction
826
 
827
  # Extract categories
828
  extract_kwargs = {
 
1172
  None, # image_folder
1173
  "", # image_description
1174
  None, # task_mode
1175
+ gr.update(variant="secondary"), # manual_btn - reset to unselected
1176
+ gr.update(variant="secondary"), # auto_extract_btn - reset to unselected
1177
  ]
1178
  # Reset category inputs
1179
  for i in range(MAX_CATEGORIES):
 
1676
 
1677
  # Manual entry button handler
1678
  def select_manual():
1679
+ visibility = update_task_visibility("manual")
1680
+ return (
1681
+ "manual",
1682
+ gr.update(variant="primary"), # manual_btn - selected
1683
+ gr.update(variant="secondary"), # auto_extract_btn - not selected
1684
+ ) + visibility
1685
 
1686
  manual_btn.click(
1687
  fn=select_manual,
1688
  inputs=[],
1689
+ outputs=[task_mode, manual_btn, auto_extract_btn, auto_extract_group, categories_group, model_group, run_btn, classify_output_group, status]
1690
  )
1691
 
1692
  # Auto-extract button handler
1693
  def select_auto_extract():
1694
+ visibility = update_task_visibility("auto_extract")
1695
+ return (
1696
+ "auto_extract",
1697
+ gr.update(variant="secondary"), # manual_btn - not selected
1698
+ gr.update(variant="primary"), # auto_extract_btn - selected
1699
+ ) + visibility
1700
 
1701
  auto_extract_btn.click(
1702
  fn=select_auto_extract,
1703
  inputs=[],
1704
+ outputs=[task_mode, manual_btn, auto_extract_btn, auto_extract_group, categories_group, model_group, run_btn, classify_output_group, status]
1705
  )
1706
 
1707
  # Run auto-extract button - extracts categories then shows next steps
 
1778
  spreadsheet_file, spreadsheet_column,
1779
  pdf_upload_type, pdf_file, pdf_folder, pdf_description, pdf_mode,
1780
  image_upload_type, image_file, image_folder, image_description,
1781
+ task_mode, manual_btn, auto_extract_btn
1782
  ] + category_inputs + [
1783
  add_category_btn, category_count,
1784
  auto_extract_group, max_categories, auto_extract_status,