Add an `empty-answer' error type and remove images in this case.
parent
b0d20eb653
commit
fb74b587e6
|
|
@ -270,7 +270,8 @@ def render_score_text(label, score, error, width_px, fontsize=18,
|
|||
def compose_label_image(base_img, label, result, hmin,
|
||||
render_fn=render_latex_text,
|
||||
draw_callback=None,
|
||||
with_error=True):
|
||||
with_error=True,
|
||||
with_empty=False):
|
||||
"""
|
||||
Composes the final image with annotations.
|
||||
|
||||
|
|
@ -287,6 +288,10 @@ def compose_label_image(base_img, label, result, hmin,
|
|||
error = result.get('error', "")
|
||||
feedbacks = result.get('feedback', [])
|
||||
|
||||
if error == "empty-answer" and not with_empty:
|
||||
return None, 0
|
||||
|
||||
|
||||
# Filter deleted items (used by reading_annotations.py)
|
||||
feedbacks = [f for f in feedbacks if "to_delete" not in f]
|
||||
|
||||
|
|
@ -436,12 +441,13 @@ def process_student(student_id, labels_data, root_dir, all_labels, overwrite):
|
|||
score = result.get('score', 0)
|
||||
d_notes[label] = str(score)
|
||||
|
||||
final_img, _ = compose_label_image(base_img, label, result, coordinates[0])
|
||||
|
||||
final_img, _ = compose_label_image(base_img, label, result, coordinates[0],
|
||||
with_empty=True)
|
||||
# 7. Save Image
|
||||
save_path = os.path.join(output_dir, f"{label}.jpg")
|
||||
final_img.save(save_path)
|
||||
label_images.append(final_img)
|
||||
if result.get('error', "") != "empty-answer":
|
||||
label_images.append(final_img)
|
||||
|
||||
# Save scores
|
||||
with open(os.path.join(output_dir, "score.json"), "w") as f:
|
||||
|
|
|
|||
|
|
@ -135,6 +135,8 @@ def process_student(args):
|
|||
render_fn=safe_render_latex,
|
||||
draw_callback=cb_renderer.callback
|
||||
)
|
||||
if final_img == None:
|
||||
continue
|
||||
|
||||
label_images.append(final_img)
|
||||
all_checkboxes.append(cb_renderer.checkboxes)
|
||||
|
|
|
|||
|
|
@ -252,6 +252,8 @@ def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_laye
|
|||
base_img, label, content['result'], content['coordinates'][0],
|
||||
with_error=False
|
||||
)
|
||||
if final_img==None:
|
||||
continue
|
||||
|
||||
# Overlay manual notes
|
||||
if has_notes:
|
||||
|
|
|
|||
Loading…
Reference in New Issue