diff --git a/annotating.py b/annotating.py index 6b15796..f2b5788 100644 --- a/annotating.py +++ b/annotating.py @@ -4,7 +4,8 @@ import json import glob from PIL import Image -MARGIN_LEFT = 200 +MARGIN_LEFT = 300 +ANNOT_WIDTH = 600 # Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates} # Coordinates are the real coordinates (hmin, hmax) of the image in the Group @@ -198,7 +199,7 @@ def render_latex_text(text, width_px, bg_color=(255, 255, 255, 255), max_lines=N final_img.alpha_composite(img) return final_img -def process_correction(root_dir, data, all_labels): +def process_correction(root_dir, data, all_labels, overwrite=False): for student_id, labels in data.items(): # Prepare output directory: Dir/Anot_CopieID @@ -208,7 +209,7 @@ def process_correction(root_dir, data, all_labels): # Check if already processed (Concat.jpg exists) concat_path = os.path.join(output_dir, "Concat.jpg") - if os.path.exists(concat_path): + if os.path.exists(concat_path) and not overwrite: print(f"Skipping Copie {student_id} (Concat.jpg exists)") continue @@ -323,7 +324,7 @@ def process_correction(root_dir, data, all_labels): # (255, 0, 0, 50) is transparent red txt_img = render_latex_text( fb['text'], - width_px=600, + width_px=ANNOT_WIDTH, bg_color=(255, 200, 200, 180), # Light Red semi-transparent max_lines=3 ) @@ -403,16 +404,17 @@ def concat_display_image(subdir): # subprocess.call(('xdg-open', save_path)) +import argparse +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Annotate copies") + parser.add_argument("root_dir", help="Directory containing the copies") + parser.add_argument("--overwrite", action="store_true", help="Reprocess even if Concat.jpg exists") -if len(sys.argv) < 2: - print("Usage: python script.py ") - sys.exit(1) - -root_dir = sys.argv[1] -labels = list(filter(None, (Path(root_dir) / "labels").read_text().splitlines())) -results = make_dictionary(root_dir) -# Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates} -# Coordinates are the real coordinates (hmin, hmax) of the image in the Group -# print(results,"\n\n\n") -process_correction(root_dir, results, labels) -# concat_anot_images(root_dir) + args = parser.parse_args() + root_dir = args.root_dir + labels = list(filter(None, (Path(root_dir) / "labels").read_text().splitlines())) + results = make_dictionary(root_dir) + # Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates} + # Coordinates are the real coordinates (hmin, hmax) of the image in the Group + # print(results,"\n\n\n") + process_correction(root_dir, results, labels,overwrite=args.overwrite)