diff --git a/annotating.py b/annotating.py index ec589c8..d5ce46f 100644 --- a/annotating.py +++ b/annotating.py @@ -103,6 +103,8 @@ import io import shutil from pdf2image import convert_from_path from PIL import Image, ImageDraw, ImageFont +import matplotlib +matplotlib.use('Agg') # Force headless rendering import matplotlib.pyplot as plt # plt.rcParams.update({ "text.usetex": True, @@ -302,8 +304,6 @@ def color(score): def render_score_text(label, score, error, width_px, fontsize=18, bg_color=(255, 255, 255, 255), with_error=True, id=None): - # 1. Calculate Color Gradient - # 2. Build highlight-text String & Properties # Wrap colored parts in < > score_str = f"{label} Note : <{score}>" @@ -321,8 +321,6 @@ def render_score_text(label, score, error, width_px, fontsize=18, fig_width = width_px / dpi chars_per_line = int(fig_width * 10) - # wrapped_text = textwrap.fill(score_str, width=chars_per_line) - # fig_height = 0.4 + 0.2 fig_height = 0.8 @@ -561,6 +559,7 @@ def process_student(student_id, labels_data, root_dir, all_labels, overwrite): def process_correction(root_dir, data, all_labels, overwrite=False): + # with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: # # Create a list of futures # futures = [] diff --git a/annotating_by_label.py b/annotating_by_label.py index 0fa4c27..43bc9be 100644 --- a/annotating_by_label.py +++ b/annotating_by_label.py @@ -19,6 +19,7 @@ def render_item(item): student_id, label, content = item pdf_path = content['pdf_path'] if not os.path.exists(pdf_path): + print("no pdf path") return None base_img, _, _ = annotating.make_base_image(pdf_path) @@ -135,7 +136,7 @@ def main(): os.makedirs(bgnot_dir, exist_ok=True) for line in lines: - labels = [l.replace(":", "").strip() for l in line.split(',') if l.strip()] + labels = [l.strip() for l in line.split(',') if l.strip()] if not labels: continue @@ -154,7 +155,6 @@ def main(): annotating_with_checks.natural_key(x[0]), annotating_with_checks.natural_key(x[1]) )) - # Render images in parallel using the pre-existing lock & render function with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: rendered = list(executor.map(render_item, items_to_render)) diff --git a/annotating_with_checks.py b/annotating_with_checks.py index 2a9b5a8..56b1cae 100644 --- a/annotating_with_checks.py +++ b/annotating_with_checks.py @@ -8,8 +8,8 @@ import img2pdf from reportlab.pdfgen import canvas # Fix for Matplotlib in threads: Set backend to non-interactive 'Agg' -# import matplotlib -# matplotlib.use('Agg') +import matplotlib +matplotlib.use('Agg') from PIL import Image, ImageDraw, ImageFont import annotating