mikaelJ46 commited on
Commit
12b55c8
Β·
verified Β·
1 Parent(s): 52451d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -530,11 +530,8 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
530
  lines=1
531
  )
532
 
533
- # Hidden file component to provide a real downloadable file
534
- questions_file = gr.File(visible=False, label="Questions File")
535
-
536
  with gr.Row():
537
- download_questions_btn = gr.Button("πŸ“₯ Download Questions")
538
  copy_btn = gr.Button("πŸ“‹ Copy Questions")
539
 
540
  # Generate questions handler
@@ -558,27 +555,25 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
558
  outputs=[questions_output, questions_output, questions_state, status_output]
559
  )
560
 
561
- # Download handler
562
  def download_qns():
563
  if not session.current_questions:
564
- return None, "⚠️ Generate questions first!"
565
  try:
566
  # Prefer PDF export; fall back to plain text if PDF library missing
567
  pdf_path = download_questions_pdf(session.current_questions, session.current_topic, session.current_grade)
568
  if pdf_path:
569
- abs_path = os.path.abspath(pdf_path)
570
- return abs_path, f"βœ… Click the download button above to save: {os.path.basename(pdf_path)}"
571
  # Fallback to text
572
  filepath = download_questions_file(session.current_questions, session.current_topic, session.current_grade)
573
- abs_path = os.path.abspath(filepath)
574
- return abs_path, f"βœ… Click the download button above to save: {os.path.basename(filepath)}"
575
  except Exception as e:
576
- return None, f"❌ Error: {str(e)}"
577
 
578
  download_questions_btn.click(
579
  fn=download_qns,
580
  inputs=[],
581
- outputs=[questions_file, status_output]
582
  )
583
 
584
  # ===== TAB 2: SUBMIT ANSWERS =====
@@ -697,9 +692,7 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
697
  )
698
 
699
  with gr.Row():
700
- download_feedback_btn = gr.Button("πŸ“₯ Download Feedback")
701
- # Hidden file component so the feedback can be downloaded
702
- feedback_file = gr.File(visible=False, label="Feedback File")
703
  save_status = gr.Textbox(
704
  label="Download Status",
705
  interactive=False
@@ -729,21 +722,20 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
729
  outputs=feedback_output
730
  )
731
 
732
- # Download feedback handler
733
  def download_feedback_handler():
734
  if not session.last_feedback:
735
- return None, "⚠️ Get AI correction first!"
736
  try:
737
  filepath = download_feedback_file(session.last_feedback, session.current_topic, session.current_grade)
738
- abs_path = os.path.abspath(filepath)
739
- return abs_path, f"βœ… Click the download button above to save: {os.path.basename(filepath)}"
740
  except Exception as e:
741
- return None, f"❌ Error: {str(e)}"
742
 
743
  download_feedback_btn.click(
744
  fn=download_feedback_handler,
745
  inputs=[],
746
- outputs=[feedback_file, save_status]
747
  )
748
 
749
  # ===== TAB 4: START NEW SESSION =====
 
530
  lines=1
531
  )
532
 
 
 
 
533
  with gr.Row():
534
+ download_questions_btn = gr.DownloadButton("πŸ“₯ Download Questions (PDF)")
535
  copy_btn = gr.Button("πŸ“‹ Copy Questions")
536
 
537
  # Generate questions handler
 
555
  outputs=[questions_output, questions_output, questions_state, status_output]
556
  )
557
 
558
+ # Download handler - returns file path for gr.DownloadButton
559
  def download_qns():
560
  if not session.current_questions:
561
+ return None
562
  try:
563
  # Prefer PDF export; fall back to plain text if PDF library missing
564
  pdf_path = download_questions_pdf(session.current_questions, session.current_topic, session.current_grade)
565
  if pdf_path:
566
+ return pdf_path
 
567
  # Fallback to text
568
  filepath = download_questions_file(session.current_questions, session.current_topic, session.current_grade)
569
+ return filepath
 
570
  except Exception as e:
571
+ return None
572
 
573
  download_questions_btn.click(
574
  fn=download_qns,
575
  inputs=[],
576
+ outputs=download_questions_btn
577
  )
578
 
579
  # ===== TAB 2: SUBMIT ANSWERS =====
 
692
  )
693
 
694
  with gr.Row():
695
+ download_feedback_btn = gr.DownloadButton("πŸ“₯ Download Feedback (TXT)")
 
 
696
  save_status = gr.Textbox(
697
  label="Download Status",
698
  interactive=False
 
722
  outputs=feedback_output
723
  )
724
 
725
+ # Download feedback handler - returns file path for gr.DownloadButton
726
  def download_feedback_handler():
727
  if not session.last_feedback:
728
+ return None
729
  try:
730
  filepath = download_feedback_file(session.last_feedback, session.current_topic, session.current_grade)
731
+ return filepath
 
732
  except Exception as e:
733
+ return None
734
 
735
  download_feedback_btn.click(
736
  fn=download_feedback_handler,
737
  inputs=[],
738
+ outputs=download_feedback_btn
739
  )
740
 
741
  # ===== TAB 4: START NEW SESSION =====