Refaire support

This commit is contained in:
2026-03-29 21:52:51 +02:00
parent 8a1eea6b3b
commit f16c0273bd
3 changed files with 156 additions and 7 deletions
+26 -2
View File
@@ -208,6 +208,8 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate annotated PDFs.")
parser.add_argument("input_path", help="Directory or specific file path")
parser.add_argument("--overwrite", action="store_true", help="Overwrite existing output files")
parser.add_argument("--refaire", action="store_true", help="Process only copies/labels defined in refaire.json") # ADD THIS LINE
args = parser.parse_args()
@@ -230,8 +232,30 @@ if __name__ == "__main__":
results = annotating.make_dictionary(root_dir)
# Filter results if a specific target ID was requested
if target_id:
# --- ADD THE REFAIRE BLOCK HERE ---
if args.refaire:
refaire_path = os.path.join(root_dir, "refaire.json")
if os.path.exists(refaire_path):
with open(refaire_path, "r", encoding="utf-8") as f:
refaire_list = json.load(f)
filtered_results = {}
for copie_name, labels_to_redo in refaire_list:
sid = copie_name.replace("Copie", "") # Extract "01" from "Copie01"
if sid in results:
if not labels_to_redo:
# Empty list: keep all labels for this Copie
filtered_results[sid] = results[sid]
else:
# Keep only the requested labels
filtered_results[sid] = {
lbl: data for lbl, data in results[sid].items()
if lbl in labels_to_redo
}
results = filtered_results
else:
print(f"Warning: --refaire flag used, but {refaire_path} not found.")
elif target_id:
if target_id in results:
results = {target_id: results[target_id]}
else: