Spaces:
Running
Running
Commit
·
028cf2d
1
Parent(s):
ae1b24b
Auto-adjust divisions parameter based on input size
Browse files- Calculate sensible divisions: min(5, max(1, num_items // 3))
- Prevents "Cannot extract N categories from chunks of only M items" error
- For 10 images: uses 3 divisions instead of default 5
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -558,6 +558,10 @@ def run_extract_categories(input_type, spreadsheet_file, spreadsheet_column,
|
|
| 558 |
}
|
| 559 |
actual_mode = mode_mapping.get(pdf_mode, "image")
|
| 560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
result = catllm.extract(
|
| 562 |
input_data=pdf_input,
|
| 563 |
api_key=actual_api_key,
|
|
@@ -565,7 +569,8 @@ def run_extract_categories(input_type, spreadsheet_file, spreadsheet_column,
|
|
| 565 |
description=pdf_description or "document",
|
| 566 |
mode=actual_mode,
|
| 567 |
user_model=model,
|
| 568 |
-
model_source=model_source
|
|
|
|
| 569 |
)
|
| 570 |
|
| 571 |
elif input_type == "Images":
|
|
@@ -584,13 +589,18 @@ def run_extract_categories(input_type, spreadsheet_file, spreadsheet_column,
|
|
| 584 |
yield None, None, "**Error:** Please upload image file(s) or a folder"
|
| 585 |
return
|
| 586 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
result = catllm.extract(
|
| 588 |
input_data=image_input,
|
| 589 |
api_key=actual_api_key,
|
| 590 |
input_type="image",
|
| 591 |
description=image_description or "images",
|
| 592 |
user_model=model,
|
| 593 |
-
model_source=model_source
|
|
|
|
| 594 |
)
|
| 595 |
|
| 596 |
else:
|
|
@@ -955,6 +965,13 @@ def run_extract_and_assign(input_type, spreadsheet_file, spreadsheet_column,
|
|
| 955 |
yield None, None, None, None, None, None, f"**Error:** Unknown input type: {input_type}"
|
| 956 |
return
|
| 957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 958 |
# Extract categories
|
| 959 |
extract_kwargs = {
|
| 960 |
'input_data': input_data,
|
|
@@ -962,7 +979,8 @@ def run_extract_and_assign(input_type, spreadsheet_file, spreadsheet_column,
|
|
| 962 |
'input_type': input_type_param,
|
| 963 |
'description': description,
|
| 964 |
'user_model': model,
|
| 965 |
-
'model_source': model_source
|
|
|
|
| 966 |
}
|
| 967 |
if mode_param:
|
| 968 |
extract_kwargs['mode'] = mode_param
|
|
|
|
| 558 |
}
|
| 559 |
actual_mode = mode_mapping.get(pdf_mode, "image")
|
| 560 |
|
| 561 |
+
# Calculate sensible divisions based on input size
|
| 562 |
+
num_items = len(pdf_input) if isinstance(pdf_input, list) else 1
|
| 563 |
+
divisions = min(5, max(1, num_items // 3))
|
| 564 |
+
|
| 565 |
result = catllm.extract(
|
| 566 |
input_data=pdf_input,
|
| 567 |
api_key=actual_api_key,
|
|
|
|
| 569 |
description=pdf_description or "document",
|
| 570 |
mode=actual_mode,
|
| 571 |
user_model=model,
|
| 572 |
+
model_source=model_source,
|
| 573 |
+
divisions=divisions
|
| 574 |
)
|
| 575 |
|
| 576 |
elif input_type == "Images":
|
|
|
|
| 589 |
yield None, None, "**Error:** Please upload image file(s) or a folder"
|
| 590 |
return
|
| 591 |
|
| 592 |
+
# Calculate sensible divisions based on input size
|
| 593 |
+
num_items = len(image_input) if isinstance(image_input, list) else 1
|
| 594 |
+
divisions = min(5, max(1, num_items // 3))
|
| 595 |
+
|
| 596 |
result = catllm.extract(
|
| 597 |
input_data=image_input,
|
| 598 |
api_key=actual_api_key,
|
| 599 |
input_type="image",
|
| 600 |
description=image_description or "images",
|
| 601 |
user_model=model,
|
| 602 |
+
model_source=model_source,
|
| 603 |
+
divisions=divisions
|
| 604 |
)
|
| 605 |
|
| 606 |
else:
|
|
|
|
| 965 |
yield None, None, None, None, None, None, f"**Error:** Unknown input type: {input_type}"
|
| 966 |
return
|
| 967 |
|
| 968 |
+
# Calculate sensible divisions based on input size
|
| 969 |
+
if isinstance(input_data, list):
|
| 970 |
+
num_items = len(input_data)
|
| 971 |
+
else:
|
| 972 |
+
num_items = 1
|
| 973 |
+
divisions = min(5, max(1, num_items // 3))
|
| 974 |
+
|
| 975 |
# Extract categories
|
| 976 |
extract_kwargs = {
|
| 977 |
'input_data': input_data,
|
|
|
|
| 979 |
'input_type': input_type_param,
|
| 980 |
'description': description,
|
| 981 |
'user_model': model,
|
| 982 |
+
'model_source': model_source,
|
| 983 |
+
'divisions': divisions
|
| 984 |
}
|
| 985 |
if mode_param:
|
| 986 |
extract_kwargs['mode'] = mode_param
|