diff --git a/annotating.py b/annotating.py index 4693b4a..c73568d 100644 --- a/annotating.py +++ b/annotating.py @@ -278,6 +278,7 @@ def render_real_latex_text(text, width_px, bg_color=(255, 255, 255, 255), max_li \\usepackage[T1]{{fontenc}} \\usepackage{{lmodern}} % Enables arbitrary font scaling \\usepackage{{amsmath, amssymb}} +\\usepackage{{mathabx}} % larger inline operators. \\usepackage{{commands}} %\\usepackage{{anyfontsize}} % replaced by lmodern \\begin{{document}} diff --git a/correction.py b/correction.py index e99c79e..1195c1f 100644 --- a/correction.py +++ b/correction.py @@ -3,6 +3,14 @@ import os import time from pathlib import Path import argparse +import prompting +import signal +from google import genai +import base64 +import shlex +import json +import threading +import concurrent.futures if len(sys.argv) < 2: sys.exit("Usage: python script.py 'InterroTest/Ex 2/Group_1.jpg' OR OR 'file1' 'file2'") @@ -36,7 +44,7 @@ for path_str in args.paths: if arg_path.is_file() and arg_path.suffix.lower() == ".jpg": # Handle individual file - # Note: assumes structure InterroTest/Ex 2/Group_1.jpg to get parents[1] + # Note: assumes structure InterroTest/Ex 2/Group_1.jpg label = arg_path.parent.name INPUT_DIR = arg_path.parent.parent.parent COPIES_DIR = INPUT_DIR / "Copies" @@ -58,124 +66,6 @@ for path_str in args.paths: for img in sub.glob("*.jpg"): tasks.append((str(img), label)) -my_prompt = """I'm giving you an image of several written answers to an exam. - -Each answer is separated by a black horizontal line, and underneath, -to the left, is indicated the ID of the answer, from `01` to `50`. - -I want you to score each answer, from 0 to 4, you may score half -points, such as 2.5. Even if a result is wrong, if the reasoning is -correct and could lead to a right answer, you should give at least -half the points. - -You also need to give feedback to the student, in french : - - which part of his answer is wrong, - - why is it wrong - - possibly, what he should have done instead. -Your feedback may contain LaTeX fragments written like `$a^2 + b^2 = c^2$`. - -If your score is not 4, you should always provide some feedback -explaining what's missing. - -For each piece of feedback, if it is related to a specific part of the -answer that is wrong, you may provide a `box_2d`, to locate this -specific part of the answer. This `box_2d` should be in the form -[ymin, xmin, ymax, xmax] normalized to 0-1000. If you do not provide -one, set `box_2d` to `null`. - -If the answer is correct, there is no need to provide feedback. You do -not have to give positive feedback, but if you do, do not provide a -`box_2d` for it. - -For example, if the student says a function is continuous when it -isn't, provide the coordinates where the word «continuous» is. If a -calculation went wrong, gives the coordinates of the step where it -goes wrong, and as feedback, what went wrong. - -Avoid giving feedback about confusing letters `n` with `m`, `x` with -`n` or `h` with `k`. If it looks wrong, assume you read it wrong, -unless the distinction is very important. - -You should also give me a measure of confidence, from 0 to 1 that you -were able to correctly understand the answer. A score below 0.5 means -that you think it is likely that you couldn't understand an important -part. - -In some case, you may find that either - - The student didn't answer the right question. Set the score to 0. - Since it could be a labeling error, indicate is by setting `error` - to \"wrong-label\". - - You can find an answer to another question of the exercice (taking - more than a couple of lines). Score the question you are supposed - to score, but set `error` to \"additional-answer\". - - The answer to the question is empty, or the student has only - rewritten the statement of the question. In this case, set `error` - to \"empty-answer\" and do not provide any kind of feedback. -If there's no error, set `error` to `\"\"`. - -You will answer using json describing a list of dictionary with a key -\"id\", and a key \"result\" that contains the \"score\", the \"confidence\", a -list \"feedback\", and possibly an \"error\". Like this example : - -[{ \"id\": \"01\", - \"result\": {\"score\" : 2.5, - \"confidence\" : 0.8, - \"feedback\": [{text: \"Un retour générique. Il faut apprendre le cours.\", box_2d: null}, - {text: \"Non, la fonction n'est pas forcément continue\", pos: [145, 280, 340, 500]}], - \"error\": \"\"} - }, - { \"id\": \"04\", - \"result\": {\"score\" : 4., - \"confidence\" : 0.9, - \"feedback\" : [] - \"error\": \"\" } - } -] - -Here is the text of the exercice (or the relevant part of the problem) -of the exam : - -``` -<> -``` - -Here is a possible correct answer : - -``` -<> -``` -<> - -You are asked to score the question or exercice labeled `<