diff --git a/gemini_for_labels.py b/gemini_for_labels.py index 04a03d2..ee048de 100644 --- a/gemini_for_labels.py +++ b/gemini_for_labels.py @@ -205,6 +205,9 @@ for path_str in args.input_paths: 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") + client = genai.Client(api_key=api_key) # Group files by Copy ID (e.g. Copie01_01.jpg -> Copie01) @@ -265,12 +268,19 @@ def process_copy_group(group_key, files): annota = AnnotationData.model_validate_json(response.text) unknown = [item.label for item in annota.list if item.label not in valid_labels_set] + name = annota.name if unknown: print(f"Error: {image_file.name} contained unknown labels: {unknown}") if attempt == 0: print("Retrying request...") continue # Retry immediately + if name not in valid_names_set: + print(f"Error: {image_file.name} returned unknown name : {name}") + if attempt == 0: + print("Retrying request...") + continue # Retry immediately + # Save result with open(output_json, "w", encoding="utf-8") as f: json.dump(annota.model_dump(), f, indent=2)