Upload app.py
Browse files
app.py
CHANGED
@@ -388,16 +388,21 @@ def classify_solution_stream(question: str, solution: str):
|
|
388 |
yield "Models not loaded", "", render(log)
|
389 |
return
|
390 |
log[-1] = "✅ Models loaded."
|
|
|
|
|
391 |
|
392 |
try:
|
393 |
# ---------- Stage 1: Conceptual ----------
|
394 |
log.append("⏳ **Stage 1: Conceptual check**")
|
395 |
yield "⏳ Working…", "Starting initial conceptual check…", render(log)
|
396 |
-
|
397 |
conceptual = run_conceptual_check(question, solution, classifier_model, classifier_tokenizer)
|
398 |
pred = conceptual["prediction"]
|
399 |
conf = conceptual["probabilities"][pred]
|
400 |
-
|
|
|
|
|
|
|
|
|
401 |
yield "⏳ Working…", f"Stage 1: {pred} (p={conf:.2%}). Now checking calculations…", render(log)
|
402 |
|
403 |
# ---------- Stage 2: Computational ----------
|
@@ -411,7 +416,7 @@ def classify_solution_stream(question: str, solution: str):
|
|
411 |
# mark stage 2 as failed
|
412 |
line_txt = computational["line_text"]
|
413 |
corr = computational["correct_calc"]
|
414 |
-
log[-1] = f"🟥 **Stage 2: Computational check** — error on line “{line_txt}” (correct: `{corr}`)"
|
415 |
classification = "computational_error"
|
416 |
explanation = (
|
417 |
"A calculation error was found.\n"
|
@@ -419,7 +424,7 @@ def classify_solution_stream(question: str, solution: str):
|
|
419 |
f"The correct calculation should be: {corr}"
|
420 |
)
|
421 |
else:
|
422 |
-
log[-1] = "✅ **Stage 2: Computational check** — no arithmetic issues found."
|
423 |
if pred == "correct":
|
424 |
classification = "correct"
|
425 |
explanation = "All calculations are correct and the overall logic appears to be sound."
|
@@ -429,7 +434,7 @@ def classify_solution_stream(question: str, solution: str):
|
|
429 |
"All calculations are correct, but there appears to be a conceptual error "
|
430 |
"in the logic or setup of the solution."
|
431 |
)
|
432 |
-
|
433 |
# final yield updates both result fields + the complete checklist
|
434 |
yield classification, explanation, render(log)
|
435 |
|
@@ -476,7 +481,7 @@ with gr.Blocks(title="Math Solution Classifier", theme=gr.themes.Soft()) as app:
|
|
476 |
["John has three apples and Mary has seven, how many apples do they have together?",
|
477 |
"They have 7 + 3 = 11 apples."],
|
478 |
["A tank holds 60 liters of fuel. A generator uses fuel at a rate of 5 liters per hour. After running for 9 hours, how many liters are still in the tank?",
|
479 |
-
"The generator uses 5 L/h × 9 h = 45 L of fuel in 9 hours
|
480 |
["What is 15% of 200?",
|
481 |
"15% = 15/100 = 0.15\n0.15 × 200 = 30"],
|
482 |
],
|
|
|
388 |
yield "Models not loaded", "", render(log)
|
389 |
return
|
390 |
log[-1] = "✅ Models loaded."
|
391 |
+
|
392 |
+
verdicts_mapping = {"correct": "Correct.", "conceptual_error": "Conceptual error.", "computational_error": "Computational error."}
|
393 |
|
394 |
try:
|
395 |
# ---------- Stage 1: Conceptual ----------
|
396 |
log.append("⏳ **Stage 1: Conceptual check**")
|
397 |
yield "⏳ Working…", "Starting initial conceptual check…", render(log)
|
|
|
398 |
conceptual = run_conceptual_check(question, solution, classifier_model, classifier_tokenizer)
|
399 |
pred = conceptual["prediction"]
|
400 |
conf = conceptual["probabilities"][pred]
|
401 |
+
if pred == "flawed":
|
402 |
+
log[-1] = f"🟥 **Stage 1: Conceptual check** — (Complete) — prediction: **{pred}** (p={conf:.2%})"
|
403 |
+
elif pred == "correct":
|
404 |
+
log[-1] = f"✅ **Stage 1: Conceptual check** — (Complete) — prediction: **{pred}** (p={conf:.2%})"
|
405 |
+
|
406 |
yield "⏳ Working…", f"Stage 1: {pred} (p={conf:.2%}). Now checking calculations…", render(log)
|
407 |
|
408 |
# ---------- Stage 2: Computational ----------
|
|
|
416 |
# mark stage 2 as failed
|
417 |
line_txt = computational["line_text"]
|
418 |
corr = computational["correct_calc"]
|
419 |
+
log[-1] = f"🟥 **Stage 2: Computational check** — (Completed; error found) — — error on line “{line_txt}” (correct: `{corr}`)"
|
420 |
classification = "computational_error"
|
421 |
explanation = (
|
422 |
"A calculation error was found.\n"
|
|
|
424 |
f"The correct calculation should be: {corr}"
|
425 |
)
|
426 |
else:
|
427 |
+
log[-1] = "✅ **Stage 2: Computational check** — (Complete) — no arithmetic issues found."
|
428 |
if pred == "correct":
|
429 |
classification = "correct"
|
430 |
explanation = "All calculations are correct and the overall logic appears to be sound."
|
|
|
434 |
"All calculations are correct, but there appears to be a conceptual error "
|
435 |
"in the logic or setup of the solution."
|
436 |
)
|
437 |
+
classification = verdicts_mapping[classification]
|
438 |
# final yield updates both result fields + the complete checklist
|
439 |
yield classification, explanation, render(log)
|
440 |
|
|
|
481 |
["John has three apples and Mary has seven, how many apples do they have together?",
|
482 |
"They have 7 + 3 = 11 apples."],
|
483 |
["A tank holds 60 liters of fuel. A generator uses fuel at a rate of 5 liters per hour. After running for 9 hours, how many liters are still in the tank?",
|
484 |
+
"The generator uses 5 L/h × 9 h = 45 L of fuel in 9 hours.\n Then, there remain 60 L + 45 L = 105 L in the tank.\n Final answer: 105 L"],
|
485 |
["What is 15% of 200?",
|
486 |
"15% = 15/100 = 0.15\n0.15 × 200 = 30"],
|
487 |
],
|