Small fixes ; Make annotating not threaded

This commit is contained in:
2026-02-28 15:02:32 +01:00
parent be390cfbb1
commit e610c80a69
4 changed files with 56 additions and 35 deletions
+21 -13
View File
@@ -180,33 +180,41 @@ def natural_key(text):
for path_str in args.input_paths:
input_arg = Path(path_str)
target_files = []
# 1. Determine which files to process
if input_arg.is_file():
INPUT_DIR = input_arg.parent
target_files = [input_arg]
elif input_arg.is_dir():
target_files = list(input_arg.glob("Copie*.pdf"))
if not target_files:
print(f"Warning: No Copie*.pdf files found in {input_arg}")
else:
print(f"Error: {input_arg} is not a valid file or directory.")
continue
# 2. Run the logic for all collected files
for target_file in target_files:
INPUT_DIR = target_file.parent
CUTLEFT_DIR = INPUT_DIR / 'Cutleft'
# Matches stem_01.jpg, stem_02.jpg, etc.
found_files = sorted(list(CUTLEFT_DIR.glob(f"{input_arg.stem}_*.jpg")),
key=natural_key)
found_files = sorted(
CUTLEFT_DIR.glob(f"{target_file.stem}_*.jpg"),
key=natural_key
)
if found_files:
image_files.extend(found_files)
else:
print(f"Warning: No variants found for {input_arg.stem} in {CUTLEFT_DIR}")
elif input_arg.is_dir():
INPUT_DIR = input_arg
CUTLEFT_DIR = INPUT_DIR / 'Cutleft'
image_files.extend(sorted(list(CUTLEFT_DIR.glob("*.jpg")), key=natural_key))
else:
print(f"Error: {input_arg} is not a valid file or directory.")
print(f"Warning: No variants found for {target_file.stem} in {CUTLEFT_DIR}")
labels_txt = (INPUT_DIR / "labels").read_text()
valid_labels_set = set(line.strip() for line in labels_txt.splitlines() if line.strip())
names_txt = (INPUT_DIR / "names").read_text()
valid_names_set = set(line.strip() for line in names_txt.splitlines() if line.strip())
valid_names_set.add("Unknown")
valid_names_set.add("Continued")
client = genai.Client(api_key=api_key)
@@ -256,7 +264,7 @@ def process_copy_group(group_key, files):
print(f"[{group_key}] Processing {image_file.name} with {len(accumulated_labels)} accumulated labels...")
for attempt in range(2)
for attempt in range(2):
try:
contents, config = generate_request(image_file, labels_txt, names_txt, accumulated_labels)