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