Refaire support
This commit is contained in:
@@ -16,6 +16,8 @@ parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--overwrite", action="store_true",
|
||||
help="Force redo requests even if output exists")
|
||||
parser.add_argument("--limit", type=int, help="limit calls to gemini rpo integer")
|
||||
parser.add_argument("--refaire", action="store_true",
|
||||
help="Redo specific copies/labels defined in refaire.json")
|
||||
args, _ = parser.parse_known_args()
|
||||
|
||||
|
||||
@@ -675,6 +677,67 @@ def process_single_task(task_tuple):
|
||||
flush_thread_log()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if args.refaire:
|
||||
refaire_path = Path(INPUT_DIR) / "refaire.json"
|
||||
overwritten_path = Path(INPUT_DIR) / "overwritten_correction.json"
|
||||
|
||||
if refaire_path.exists():
|
||||
with open(refaire_path, "r", encoding="utf-8") as f:
|
||||
refaire_list = json.load(f)
|
||||
|
||||
overwritten_data = []
|
||||
if overwritten_path.exists():
|
||||
with open(overwritten_path, "r", encoding="utf-8") as f:
|
||||
overwritten_data = json.load(f)
|
||||
|
||||
dirty_results = False
|
||||
|
||||
for copie_name, labels in refaire_list:
|
||||
pid = copie_name.replace("Copie", "")
|
||||
copie_dir = Path(INPUT_DIR) / copie_name
|
||||
|
||||
# If list is empty, redo all labels available for this Copie
|
||||
if not labels:
|
||||
labels = [p.stem for p in copie_dir.glob("*.pdf")]
|
||||
|
||||
for label in labels:
|
||||
# 1. Extract and backup old corrections
|
||||
if label in results:
|
||||
for batch in results[label]:
|
||||
to_remove = None
|
||||
for item in batch:
|
||||
if item.get("id") == pid:
|
||||
to_remove = item
|
||||
break
|
||||
if to_remove:
|
||||
batch.remove(to_remove)
|
||||
overwritten_data.append({
|
||||
"pid": pid,
|
||||
"label": label,
|
||||
"data": to_remove,
|
||||
"timestamp": time.time()
|
||||
})
|
||||
dirty_results = True
|
||||
# Clean up empty batches
|
||||
results[label] = [b for b in results[label] if b]
|
||||
|
||||
# 2. Make new group and add to tasks
|
||||
pdf_path = copie_dir / f"{label}.pdf"
|
||||
if pdf_path.exists():
|
||||
idx = get_next_group_idx(INPUT_DIR, label)
|
||||
height = grouping.get_pdf_height(str(pdf_path))
|
||||
grouping.create_jpg(label, idx, [(pid, str(pdf_path), height)], INPUT_DIR)
|
||||
new_group_path = str(Path(INPUT_DIR) / label / f"Group_{idx+1}.jpg")
|
||||
tasks_to_process.append((new_group_path, label))
|
||||
|
||||
if dirty_results:
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
json.dump(results, f, indent=2)
|
||||
with open(overwritten_path, "w", encoding="utf-8") as f:
|
||||
json.dump(overwritten_data, f, indent=2)
|
||||
else:
|
||||
print(f"Warning: --refaire flag used, but {refaire_path} not found.", file=sys.stderr)
|
||||
|
||||
print(f"Starting processing on {len(tasks_to_process)} tasks with {NB_THREADS} threads...")
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=NB_THREADS) as executor:
|
||||
|
||||
Reference in New Issue
Block a user