Upload app.py
Browse files
app.py
CHANGED
|
@@ -41,8 +41,6 @@ logger = logging.getLogger(__name__)
|
|
| 41 |
label_mapping = {0: "✅ Correct", 1: "🤔 Conceptually Flawed", 2: "🔢 Computationally Flawed"}
|
| 42 |
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
# ===================================================================
|
| 47 |
# 1. DEFINE CUSTOM CLASSIFIER (Required for Phi-4)
|
| 48 |
# ===================================================================
|
|
@@ -165,7 +163,7 @@ classifier_tokenizer = None
|
|
| 165 |
|
| 166 |
def load_model():
|
| 167 |
"""Load your trained model here"""
|
| 168 |
-
global gemma_model, gemma_tokenizer, classifier_model, classifier_tokenizer
|
| 169 |
|
| 170 |
try:
|
| 171 |
device = DEVICE
|
|
@@ -238,6 +236,8 @@ def run_conceptual_check(question: str, solution: str, model, tokenizer) -> dict
|
|
| 238 |
"""
|
| 239 |
STAGE 1: Runs the Phi-4 classifier with memory optimizations.
|
| 240 |
"""
|
|
|
|
|
|
|
| 241 |
input_text = f"{CLASSIFIER_SYSTEM_PROMPT}\n\n### Problem:\n{question}\n\n### Answer:\n{solution}"
|
| 242 |
inputs = tokenizer(
|
| 243 |
input_text,
|
|
@@ -267,6 +267,8 @@ def run_computational_check(solution: str, model, tokenizer, batch_size: int = 3
|
|
| 267 |
STAGE 2: Splits a solution into lines and performs a batched computational check.
|
| 268 |
(Corrected to handle PEMDAS/parentheses)
|
| 269 |
"""
|
|
|
|
|
|
|
| 270 |
lines = [line.strip() for line in solution.strip().split('\n') if line.strip() and "FINAL ANSWER:" not in line.upper()]
|
| 271 |
if not lines:
|
| 272 |
return {"error": False}
|
|
@@ -424,7 +426,7 @@ with gr.Blocks(title="Math Solution Classifier", theme=gr.themes.Soft()) as app:
|
|
| 424 |
classify_btn.click(
|
| 425 |
fn=classify_solution,
|
| 426 |
inputs=[question_input, solution_input],
|
| 427 |
-
outputs=[classification_output,
|
| 428 |
)
|
| 429 |
|
| 430 |
if __name__ == "__main__":
|
|
|
|
| 41 |
label_mapping = {0: "✅ Correct", 1: "🤔 Conceptually Flawed", 2: "🔢 Computationally Flawed"}
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
| 44 |
# ===================================================================
|
| 45 |
# 1. DEFINE CUSTOM CLASSIFIER (Required for Phi-4)
|
| 46 |
# ===================================================================
|
|
|
|
| 163 |
|
| 164 |
def load_model():
|
| 165 |
"""Load your trained model here"""
|
| 166 |
+
global gemma_model, gemma_tokenizer, classifier_model, classifier_tokenizer
|
| 167 |
|
| 168 |
try:
|
| 169 |
device = DEVICE
|
|
|
|
| 236 |
"""
|
| 237 |
STAGE 1: Runs the Phi-4 classifier with memory optimizations.
|
| 238 |
"""
|
| 239 |
+
device = DEVICE
|
| 240 |
+
|
| 241 |
input_text = f"{CLASSIFIER_SYSTEM_PROMPT}\n\n### Problem:\n{question}\n\n### Answer:\n{solution}"
|
| 242 |
inputs = tokenizer(
|
| 243 |
input_text,
|
|
|
|
| 267 |
STAGE 2: Splits a solution into lines and performs a batched computational check.
|
| 268 |
(Corrected to handle PEMDAS/parentheses)
|
| 269 |
"""
|
| 270 |
+
device = DEVICE
|
| 271 |
+
|
| 272 |
lines = [line.strip() for line in solution.strip().split('\n') if line.strip() and "FINAL ANSWER:" not in line.upper()]
|
| 273 |
if not lines:
|
| 274 |
return {"error": False}
|
|
|
|
| 426 |
classify_btn.click(
|
| 427 |
fn=classify_solution,
|
| 428 |
inputs=[question_input, solution_input],
|
| 429 |
+
outputs=[classification_output, explanation_output]
|
| 430 |
)
|
| 431 |
|
| 432 |
if __name__ == "__main__":
|