Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -678,18 +678,19 @@ def append_chatgpt_verification(initial_response, sympy_correct, final_verificat
|
|
678 |
# Get ChatGPT's verification
|
679 |
chatgpt_verification = verify_with_chatgpt(question, solution_text)
|
680 |
|
681 |
-
#
|
682 |
-
|
|
|
|
|
683 |
|
684 |
-
return full_response
|
685 |
-
|
686 |
except Exception as e:
|
687 |
logger.error(f"Error in verification process: {str(e)}")
|
688 |
return initial_response + f"\n\nError in ChatGPT verification: {str(e)}"
|
689 |
|
690 |
-
def generate_question(subject, difficulty, question_type, use_enhancement=False):
|
691 |
"""Generate a single math question with additional verification"""
|
692 |
try:
|
|
|
693 |
if not os.environ.get('ANTHROPIC_API_KEY'):
|
694 |
logger.error("Anthropic API key not found")
|
695 |
return "Error: Anthropic API key not configured", None, None
|
@@ -858,11 +859,12 @@ j. **Concluding and Intuitive Explanations**
|
|
858 |
|
859 |
# Execute SymPy code and append results
|
860 |
sympy_output = extract_and_run_sympy_code_simple(response_text)
|
|
|
|
|
|
|
|
|
861 |
|
862 |
if sympy_output:
|
863 |
-
has_discrepancy = False # Initialize here
|
864 |
-
sympy_correct = None
|
865 |
-
revised_solution = None
|
866 |
if "Error" not in sympy_output:
|
867 |
resolution_text, has_discrepancy, revised_solution, sympy_correct = check_and_resolve_discrepancy(response_text, sympy_output)
|
868 |
response_text = f"{response_text}\n\nSymPy Verification Results:\n```\n{sympy_output}\n```\n\nVerification Analysis:\n{resolution_text}"
|
@@ -1191,11 +1193,12 @@ with gr.Blocks() as interface:
|
|
1191 |
|
1192 |
# Add ChatGPT verification toggle
|
1193 |
chatgpt_verify = gr.Radio(
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
|
|
1199 |
|
1200 |
generate_btn = gr.Button("Generate Question")
|
1201 |
|
|
|
678 |
# Get ChatGPT's verification
|
679 |
chatgpt_verification = verify_with_chatgpt(question, solution_text)
|
680 |
|
681 |
+
if chatgpt_verification: # Add this check
|
682 |
+
full_response = f"{initial_response}\n\nChatGPT Verification and Grading:\n{chatgpt_verification}"
|
683 |
+
return full_response
|
684 |
+
return initial_response
|
685 |
|
|
|
|
|
686 |
except Exception as e:
|
687 |
logger.error(f"Error in verification process: {str(e)}")
|
688 |
return initial_response + f"\n\nError in ChatGPT verification: {str(e)}"
|
689 |
|
690 |
+
def generate_question(subject, difficulty, question_type, use_enhancement=False, include_chatgpt="no"):
|
691 |
"""Generate a single math question with additional verification"""
|
692 |
try:
|
693 |
+
logger.debug(f"ChatGPT verification: {'enabled' if include_chatgpt == 'yes' else 'disabled'}")
|
694 |
if not os.environ.get('ANTHROPIC_API_KEY'):
|
695 |
logger.error("Anthropic API key not found")
|
696 |
return "Error: Anthropic API key not configured", None, None
|
|
|
859 |
|
860 |
# Execute SymPy code and append results
|
861 |
sympy_output = extract_and_run_sympy_code_simple(response_text)
|
862 |
+
has_discrepancy = False # Initialize outside the if block
|
863 |
+
sympy_correct = None
|
864 |
+
revised_solution = None
|
865 |
+
final_verification = None
|
866 |
|
867 |
if sympy_output:
|
|
|
|
|
|
|
868 |
if "Error" not in sympy_output:
|
869 |
resolution_text, has_discrepancy, revised_solution, sympy_correct = check_and_resolve_discrepancy(response_text, sympy_output)
|
870 |
response_text = f"{response_text}\n\nSymPy Verification Results:\n```\n{sympy_output}\n```\n\nVerification Analysis:\n{resolution_text}"
|
|
|
1193 |
|
1194 |
# Add ChatGPT verification toggle
|
1195 |
chatgpt_verify = gr.Radio(
|
1196 |
+
choices=["yes", "no"],
|
1197 |
+
label="Include ChatGPT Verification",
|
1198 |
+
info="Enable/disable ChatGPT grading (saves credits)",
|
1199 |
+
value="no" # Default to off to save credits
|
1200 |
+
)
|
1201 |
+
|
1202 |
|
1203 |
generate_btn = gr.Button("Generate Question")
|
1204 |
|