Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -353,7 +353,7 @@ def enhance_prompt_with_proofs(system_prompt, subject, topic):
|
|
353 |
# Add specific instructions for using the examples
|
354 |
enhanced_prompt = f"""{system_prompt}
|
355 |
ADDITIONAL PROOF GUIDELINES:
|
356 |
-
1. Consider the following proof examples from established
|
357 |
2. Maintain similar level of rigor and detail
|
358 |
3. Use similar proof techniques where applicable
|
359 |
4. Follow similar notation and presentation style
|
@@ -508,7 +508,7 @@ The computation question MAY NOT:
|
|
508 |
}
|
509 |
return problem_type_additions.get(question_type, "")
|
510 |
|
511 |
-
def generate_question(subject, difficulty, question_type):
|
512 |
"""Generate a single math question with additional verification"""
|
513 |
try:
|
514 |
if not os.environ.get('ANTHROPIC_API_KEY'):
|
@@ -516,6 +516,7 @@ def generate_question(subject, difficulty, question_type):
|
|
516 |
return "Error: Anthropic API key not configured", None, None
|
517 |
|
518 |
logger.debug(f"Generating {question_type} question for subject: {subject} at difficulty level: {difficulty}")
|
|
|
519 |
|
520 |
# Check rate limit
|
521 |
now = datetime.now()
|
@@ -589,8 +590,7 @@ STRICT REQUIREMENTS:
|
|
589 |
- Connect each step with a rationale
|
590 |
- Always justify the existence of bounds
|
591 |
- If you conclude certain terms vanish in a limit, clearly justify why
|
592 |
-
-
|
593 |
-
themselves should provide a clear outline of the main aspects of the proof
|
594 |
- In notes after the proof, if you observe aspects of the problem that might confuse students, address them."""
|
595 |
|
596 |
#Consider
|
@@ -599,9 +599,12 @@ STRICT REQUIREMENTS:
|
|
599 |
#- Import specific functions instead of using 'from sympy import *'
|
600 |
#- Print results of each calculation step
|
601 |
|
602 |
-
|
603 |
-
if subject == "Real Analysis" and question_type == "proof":
|
|
|
604 |
system_prompt = enhance_prompt_with_proofs(system_prompt, subject, selected_topic)
|
|
|
|
|
605 |
|
606 |
logger.debug("Sending request to Anthropic API")
|
607 |
message = anthropic.messages.create(
|
@@ -934,6 +937,14 @@ with gr.Blocks() as interface:
|
|
934 |
info="Select the type of question you want",
|
935 |
value="computation"
|
936 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
937 |
|
938 |
generate_btn = gr.Button("Generate Question")
|
939 |
|
@@ -949,12 +960,14 @@ with gr.Blocks() as interface:
|
|
949 |
questions_file = gr.File(label="Question Only (LaTeX)")
|
950 |
full_file = gr.File(label="Question with Solution (LaTeX)")
|
951 |
|
|
|
952 |
generate_btn.click(
|
953 |
generate_question,
|
954 |
inputs=[
|
955 |
subject_dropdown,
|
956 |
difficulty_slider,
|
957 |
-
question_type
|
|
|
958 |
],
|
959 |
outputs=[output_text, questions_file, full_file]
|
960 |
)
|
|
|
353 |
# Add specific instructions for using the examples
|
354 |
enhanced_prompt = f"""{system_prompt}
|
355 |
ADDITIONAL PROOF GUIDELINES:
|
356 |
+
1. Consider the following proof examples from an established textbook
|
357 |
2. Maintain similar level of rigor and detail
|
358 |
3. Use similar proof techniques where applicable
|
359 |
4. Follow similar notation and presentation style
|
|
|
508 |
}
|
509 |
return problem_type_additions.get(question_type, "")
|
510 |
|
511 |
+
def generate_question(subject, difficulty, question_type, use_enhancement=False):
|
512 |
"""Generate a single math question with additional verification"""
|
513 |
try:
|
514 |
if not os.environ.get('ANTHROPIC_API_KEY'):
|
|
|
516 |
return "Error: Anthropic API key not configured", None, None
|
517 |
|
518 |
logger.debug(f"Generating {question_type} question for subject: {subject} at difficulty level: {difficulty}")
|
519 |
+
logger.debug(f"Textbook enhancement: {'enabled' if use_enhancement else 'disabled'}")
|
520 |
|
521 |
# Check rate limit
|
522 |
now = datetime.now()
|
|
|
590 |
- Connect each step with a rationale
|
591 |
- Always justify the existence of bounds
|
592 |
- If you conclude certain terms vanish in a limit, clearly justify why
|
593 |
+
- If you state that a function has a certain characteristic, such as being Riemann integrable for example, clearly explain why
|
|
|
594 |
- In notes after the proof, if you observe aspects of the problem that might confuse students, address them."""
|
595 |
|
596 |
#Consider
|
|
|
599 |
#- Import specific functions instead of using 'from sympy import *'
|
600 |
#- Print results of each calculation step
|
601 |
|
602 |
+
# Only enhance the prompt if explicitly requested AND it's a Real Analysis proof
|
603 |
+
if use_enhancement and subject == "Real Analysis" and question_type == "proof":
|
604 |
+
logger.debug("Applying textbook enhancement to prompt")
|
605 |
system_prompt = enhance_prompt_with_proofs(system_prompt, subject, selected_topic)
|
606 |
+
else:
|
607 |
+
logger.debug("Skipping textbook enhancement")
|
608 |
|
609 |
logger.debug("Sending request to Anthropic API")
|
610 |
message = anthropic.messages.create(
|
|
|
937 |
info="Select the type of question you want",
|
938 |
value="computation"
|
939 |
)
|
940 |
+
|
941 |
+
# Add the new enhancement checkbox
|
942 |
+
use_enhancement = gr.Radio(
|
943 |
+
choices=["yes", "no"],
|
944 |
+
label="Enhance with Textbook Material",
|
945 |
+
info="Include relevant textbook examples to guide question generation",
|
946 |
+
value="no"
|
947 |
+
)
|
948 |
|
949 |
generate_btn = gr.Button("Generate Question")
|
950 |
|
|
|
960 |
questions_file = gr.File(label="Question Only (LaTeX)")
|
961 |
full_file = gr.File(label="Question with Solution (LaTeX)")
|
962 |
|
963 |
+
# Update the click event to include the new parameter
|
964 |
generate_btn.click(
|
965 |
generate_question,
|
966 |
inputs=[
|
967 |
subject_dropdown,
|
968 |
difficulty_slider,
|
969 |
+
question_type,
|
970 |
+
use_enhancement
|
971 |
],
|
972 |
outputs=[output_text, questions_file, full_file]
|
973 |
)
|