Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -401,17 +401,19 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
|
|
| 401 |
with gr.Row():
|
| 402 |
generate_btn = gr.Button("π Generate 20 Questions", variant="primary", size="lg")
|
| 403 |
|
| 404 |
-
questions_output = gr.
|
| 405 |
-
|
| 406 |
-
lines=20,
|
| 407 |
elem_classes="question-display"
|
| 408 |
)
|
| 409 |
-
|
| 410 |
status_output = gr.Textbox(
|
| 411 |
label="Status",
|
| 412 |
interactive=False,
|
| 413 |
lines=1
|
| 414 |
)
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
with gr.Row():
|
| 417 |
download_questions_btn = gr.Button("π₯ Download Questions")
|
|
@@ -428,7 +430,9 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
|
|
| 428 |
session.current_grade = grade
|
| 429 |
session.current_topic = topic
|
| 430 |
|
| 431 |
-
|
|
|
|
|
|
|
| 432 |
|
| 433 |
generate_btn.click(
|
| 434 |
fn=generate_and_display,
|
|
@@ -439,17 +443,18 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
|
|
| 439 |
# Download handler
|
| 440 |
def download_qns():
|
| 441 |
if not session.current_questions:
|
| 442 |
-
return "β οΈ Generate questions first!"
|
| 443 |
try:
|
| 444 |
filepath = download_questions_file(session.current_questions, session.current_topic, session.current_grade)
|
| 445 |
-
|
|
|
|
| 446 |
except Exception as e:
|
| 447 |
-
return f"β Error: {str(e)}"
|
| 448 |
|
| 449 |
download_questions_btn.click(
|
| 450 |
fn=download_qns,
|
| 451 |
inputs=[],
|
| 452 |
-
outputs=status_output
|
| 453 |
)
|
| 454 |
|
| 455 |
# ===== TAB 2: SUBMIT ANSWERS =====
|
|
@@ -569,6 +574,8 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
|
|
| 569 |
|
| 570 |
with gr.Row():
|
| 571 |
download_feedback_btn = gr.Button("π₯ Download Feedback")
|
|
|
|
|
|
|
| 572 |
save_status = gr.Textbox(
|
| 573 |
label="Download Status",
|
| 574 |
interactive=False
|
|
@@ -601,17 +608,17 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
|
|
| 601 |
# Download feedback handler
|
| 602 |
def download_feedback_handler():
|
| 603 |
if not session.last_feedback:
|
| 604 |
-
return "β οΈ Get AI correction first!"
|
| 605 |
try:
|
| 606 |
filepath = download_feedback_file(session.last_feedback, session.current_topic, session.current_grade)
|
| 607 |
-
return f"β
Downloaded! File: {filepath}"
|
| 608 |
except Exception as e:
|
| 609 |
-
return f"β Error: {str(e)}"
|
| 610 |
|
| 611 |
download_feedback_btn.click(
|
| 612 |
fn=download_feedback_handler,
|
| 613 |
inputs=[],
|
| 614 |
-
outputs=save_status
|
| 615 |
)
|
| 616 |
|
| 617 |
# ===== TAB 4: START NEW SESSION =====
|
|
|
|
| 401 |
with gr.Row():
|
| 402 |
generate_btn = gr.Button("π Generate 20 Questions", variant="primary", size="lg")
|
| 403 |
|
| 404 |
+
questions_output = gr.Markdown(
|
| 405 |
+
value="",
|
|
|
|
| 406 |
elem_classes="question-display"
|
| 407 |
)
|
| 408 |
+
|
| 409 |
status_output = gr.Textbox(
|
| 410 |
label="Status",
|
| 411 |
interactive=False,
|
| 412 |
lines=1
|
| 413 |
)
|
| 414 |
+
|
| 415 |
+
# Hidden file component to provide a real downloadable file
|
| 416 |
+
questions_file = gr.File(visible=False, label="Questions File")
|
| 417 |
|
| 418 |
with gr.Row():
|
| 419 |
download_questions_btn = gr.Button("π₯ Download Questions")
|
|
|
|
| 430 |
session.current_grade = grade
|
| 431 |
session.current_topic = topic
|
| 432 |
|
| 433 |
+
# For Markdown display, keep spacing and simple formatting
|
| 434 |
+
md_text = "\n\n".join([f"**{i+1}.** {q.split('.',1)[1].strip() if '.' in q else q}" for i, q in enumerate(questions_list)])
|
| 435 |
+
return md_text, md_text, questions_list, f"β
Generated {len(questions_list)} questions on {topic}"
|
| 436 |
|
| 437 |
generate_btn.click(
|
| 438 |
fn=generate_and_display,
|
|
|
|
| 443 |
# Download handler
|
| 444 |
def download_qns():
|
| 445 |
if not session.current_questions:
|
| 446 |
+
return None, "β οΈ Generate questions first!"
|
| 447 |
try:
|
| 448 |
filepath = download_questions_file(session.current_questions, session.current_topic, session.current_grade)
|
| 449 |
+
# Return the file path for gr.File and a friendly status
|
| 450 |
+
return filepath, f"β
Downloaded! File: {os.path.abspath(filepath)}"
|
| 451 |
except Exception as e:
|
| 452 |
+
return None, f"β Error: {str(e)}"
|
| 453 |
|
| 454 |
download_questions_btn.click(
|
| 455 |
fn=download_qns,
|
| 456 |
inputs=[],
|
| 457 |
+
outputs=[questions_file, status_output]
|
| 458 |
)
|
| 459 |
|
| 460 |
# ===== TAB 2: SUBMIT ANSWERS =====
|
|
|
|
| 574 |
|
| 575 |
with gr.Row():
|
| 576 |
download_feedback_btn = gr.Button("π₯ Download Feedback")
|
| 577 |
+
# Hidden file component so the feedback can be downloaded
|
| 578 |
+
feedback_file = gr.File(visible=False, label="Feedback File")
|
| 579 |
save_status = gr.Textbox(
|
| 580 |
label="Download Status",
|
| 581 |
interactive=False
|
|
|
|
| 608 |
# Download feedback handler
|
| 609 |
def download_feedback_handler():
|
| 610 |
if not session.last_feedback:
|
| 611 |
+
return None, "β οΈ Get AI correction first!"
|
| 612 |
try:
|
| 613 |
filepath = download_feedback_file(session.last_feedback, session.current_topic, session.current_grade)
|
| 614 |
+
return filepath, f"β
Downloaded! File: {os.path.abspath(filepath)}"
|
| 615 |
except Exception as e:
|
| 616 |
+
return None, f"β Error: {str(e)}"
|
| 617 |
|
| 618 |
download_feedback_btn.click(
|
| 619 |
fn=download_feedback_handler,
|
| 620 |
inputs=[],
|
| 621 |
+
outputs=[feedback_file, save_status]
|
| 622 |
)
|
| 623 |
|
| 624 |
# ===== TAB 4: START NEW SESSION =====
|