Small fixes ; Make annotating not threaded
This commit is contained in:
+24
-11
@@ -124,6 +124,11 @@ def normalize_mathtext(text):
|
||||
text = text.replace("\\\\", "\\")
|
||||
text = text.replace("\\llbracket", "[\\![")
|
||||
text = text.replace("\\rrbracket", "]\\!]")
|
||||
text = text.replace("\\R", "\\mathbb{R}")
|
||||
text = text.replace("\\N", "\\mathbb{N}")
|
||||
text = text.replace("\\Z", "\\mathbb{Z}")
|
||||
text = text.replace("\\C", "\\mathbb{C}")
|
||||
text = text.replace("\\Q", "\\mathbb{Q}")
|
||||
# Sometimes, Gemini doesn't escape enough. In the json, you should have \\f
|
||||
text = text.replace('\f', r'\f')
|
||||
text = re.sub('\u0010', "", text)
|
||||
@@ -214,8 +219,10 @@ def render_latex_text(text, width_px, bg_color=(255, 255, 255, 255), max_lines=N
|
||||
final_img.alpha_composite(img)
|
||||
return final_img
|
||||
|
||||
import matplotlib.colors as mcolors
|
||||
|
||||
def render_score_text(label, score, error, width_px, fontsize=18,
|
||||
bg_color=(255, 255, 255, 255)
|
||||
bg_color=(255, 255, 255, 255),
|
||||
with_error=True):
|
||||
# 1. Calculate Color Gradient (0.0=DarkRed -> 4.0=Green)
|
||||
# Clamp score between 0 and 4
|
||||
@@ -303,7 +310,7 @@ def compose_label_image(base_img, label, result, hmin,
|
||||
header_elements = []
|
||||
|
||||
img_score = render_score_text(label, score, error, base_img.width // 2,
|
||||
fontsize=18, with_error)
|
||||
fontsize=18, with_error=with_error)
|
||||
header_elements.append({"type": "score", "img": img_score, "data": result})
|
||||
|
||||
# Global Feedbacks
|
||||
@@ -466,16 +473,22 @@ 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 = []
|
||||
for student_id, labels in sorted(data.items()):
|
||||
futures.append(
|
||||
executor.submit(process_student, student_id, labels, root_dir, all_labels, overwrite)
|
||||
)
|
||||
# with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
||||
# # Create a list of futures
|
||||
# futures = []
|
||||
# for student_id, labels in sorted(data.items()):
|
||||
# futures.append(
|
||||
# executor.submit(process_student, student_id, labels, root_dir, all_labels, overwrite)
|
||||
# )
|
||||
|
||||
# Wait for all threads to complete
|
||||
concurrent.futures.wait(futures)
|
||||
# # Wait for all threads to complete
|
||||
# concurrent.futures.wait(futures)
|
||||
|
||||
# Ne pas thread cette applications
|
||||
# 1. Il faut protéger les appels à matplotlib
|
||||
# 2. tu vas perdre les erreurs
|
||||
for student_id, labels in sorted(data.items()):
|
||||
process_student(student_id, labels, root_dir, all_labels, overwrite)
|
||||
|
||||
import argparse
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user