Gemini for labels
parent
7575f61dbd
commit
e79059ef64
|
|
@ -167,30 +167,40 @@ def generate_request(file, labels, names, context_labels):
|
|||
return (contents, generate_content_config)
|
||||
|
||||
# Argument Parsing
|
||||
parser = argparse.ArgumentParser(description="Process a directory or specific file using Gemini.")
|
||||
parser.add_argument("input_path", help="The input directory or specific file")
|
||||
parser = argparse.ArgumentParser(description="Process a directory or specific files using Gemini.")
|
||||
parser.add_argument("input_paths", nargs='+', help="The input directory or specific files")
|
||||
parser.add_argument("--overwrite", action="store_true", help="Regenerate output even if it exists")
|
||||
args = parser.parse_args()
|
||||
|
||||
input_arg = Path(args.input_path)
|
||||
# input_arg = Path(args.input_path)
|
||||
image_files = []
|
||||
|
||||
# Setup Paths and Files
|
||||
if input_arg.is_file():
|
||||
def natural_key(text):
|
||||
return [int(c) if c.isdigit() else c.lower() for c in re.split(r'(\d+)', str(text))]
|
||||
|
||||
for path_str in args.input_paths:
|
||||
input_arg = Path(path_str)
|
||||
|
||||
if input_arg.is_file():
|
||||
INPUT_DIR = input_arg.parent
|
||||
CUTLEFT_DIR = INPUT_DIR / 'Cutleft'
|
||||
# For a single file, we verify it exists but we might miss context if we don't look for siblings
|
||||
# Simplification: We add just this file, context will be empty.
|
||||
target_image = CUTLEFT_DIR / f"{input_arg.stem}.jpg"
|
||||
if target_image.exists():
|
||||
image_files = [target_image]
|
||||
|
||||
# Matches stem_01.jpg, stem_02.jpg, etc.
|
||||
found_files = sorted(list(CUTLEFT_DIR.glob(f"{input_arg.stem}_*.jpg")),
|
||||
key=natural_key)
|
||||
|
||||
if found_files:
|
||||
image_files.extend(found_files)
|
||||
else:
|
||||
print(f"Error: {target_image} not found.")
|
||||
sys.exit(1)
|
||||
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 = sorted(list(CUTLEFT_DIR.glob("*.jpg")))
|
||||
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.")
|
||||
|
||||
labels_txt = (INPUT_DIR / "labels").read_text()
|
||||
names_txt = (INPUT_DIR / "names").read_text()
|
||||
|
|
@ -240,7 +250,7 @@ def process_copy_group(group_key, files):
|
|||
pass # If read fails, next part has no context
|
||||
continue
|
||||
|
||||
print(f"[{group_key}] Processing {image_file.name} with {len(accumulated_labels)} ctx items...")
|
||||
print(f"[{group_key}] Processing {image_file.name} with {len(accumulated_labels)} accumulated labels...")
|
||||
|
||||
try:
|
||||
contents, config = generate_request(image_file, labels_txt, names_txt, accumulated_labels)
|
||||
Loading…
Reference in New Issue