mikaelJ46 commited on
Commit
1734ffd
·
verified ·
1 Parent(s): 63e49c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -90
app.py CHANGED
@@ -698,40 +698,44 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
698
  return f"Welcome, {session.student_name}!"
699
 
700
  student_name_input.change(update_student_name, student_name_input, None)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
  # Shared question display (placed below name and above the tabs to avoid large empty header)
702
  questions_display = gr.HTML(value="", elem_classes="question-display")
703
 
704
  with gr.Tabs():
705
  # ===== TAB 1: GENERATE QUESTIONS =====
706
  with gr.Tab("1️⃣ Generate Questions"):
707
- gr.Markdown("### Step 1: Generate Practice Questions\n\nChoose the Grade, Subject and Topic, then set the Number of Questions (1–100).")
708
-
709
- with gr.Row():
710
- grade_input = gr.Dropdown(
711
- choices=["Primary 6", "Primary 7"],
712
- label="Grade Level",
713
- value="Primary 7"
714
- )
715
- subject_input = gr.Dropdown(
716
- choices=["Mathematics", "English", "Social Studies", "Science"],
717
- label="Subject",
718
- value="Mathematics"
719
- )
720
- topic_input = gr.Dropdown(
721
- label="Topic",
722
- choices=syllabus_topics["Primary 7"]["Mathematics"],
723
- value=syllabus_topics["Primary 7"]["Mathematics"][0]
724
- )
725
-
726
- # Update topics when grade or subject changes
727
- def update_topics(grade, subject):
728
- topics = syllabus_topics.get(grade, {}).get(subject, [])
729
- if not topics:
730
- topics = ["General - " + subject]
731
- return gr.Dropdown(choices=topics, value=topics[0])
732
-
733
- grade_input.change(update_topics, [grade_input, subject_input], topic_input)
734
- subject_input.change(update_topics, [grade_input, subject_input], topic_input)
735
 
736
  with gr.Row():
737
  num_questions_input = gr.Slider(minimum=1, maximum=100, step=1, value=20, label="Number of Questions")
@@ -769,7 +773,7 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
769
 
770
  generate_btn.click(
771
  fn=generate_and_display,
772
- inputs=[grade_input, subject_input, topic_input, num_questions_input],
773
  outputs=[questions_display, questions_state, status_output]
774
  )
775
  # Download handler - returns file path for gr.DownloadButton
@@ -799,55 +803,50 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
799
  gr.Markdown("### Step 2: Answer the Questions")
800
  gr.Markdown("Write out your working and answers. You can use any of the three methods below.")
801
 
802
- # Two-column layout: left = questions, right = answer methods
 
803
  with gr.Row():
804
- with gr.Column(scale=6):
805
- gr.Markdown("**Questions (keep visible while answering)**")
806
- # show the same shared questions_display here
807
- q_left = questions_display
808
- with gr.Column(scale=6):
809
- with gr.Row():
810
- method_info = gr.Textbox(
811
- label="How to Submit Answers",
812
- value="Method 1: Draw/Write in canvas\nMethod 2: Upload photo of your written work\nMethod 3: Type your answers directly",
 
 
 
 
 
 
 
 
 
 
 
 
813
  interactive=False,
814
- lines=3
815
  )
816
 
817
- with gr.Tabs():
818
- # Method 1: Draw
819
- with gr.Tab("✏️ Draw Answers"):
820
- canvas = gr.Sketchpad(
821
- label="Draw or write your answers here",
822
- type="pil",
823
- height=500,
824
- brush=gr.Brush(
825
- colors=["#000000", "#0000FF", "#FF0000"],
826
- default_size=4
827
- )
828
- )
829
- canvas_status = gr.Textbox(
830
- label="Canvas Status",
831
- interactive=False,
832
- value="Ready to draw"
833
- )
834
-
835
- # Method 2: Upload
836
- with gr.Tab("📸 Upload Photo"):
837
- upload_image = gr.Image(
838
- label="Upload photo of your written work",
839
- type="pil",
840
- height=500
841
- )
842
- upload_status = gr.Textbox(
843
- label="Upload Status",
844
- interactive=False,
845
- value="Ready to upload"
846
- )
847
-
848
- # Method 3: Type
849
- with gr.Tab(" Type Answers"):
850
- gr.Markdown("""
851
  ### 📝 Type Your Answers
852
 
853
  **Instructions:** Type each answer in the box below. Use one of these formats:
@@ -874,24 +873,24 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
874
  Q2: Your answer here
875
  Q3: Your answer here
876
  ```
877
- """)
878
-
879
- typed_answers = gr.Textbox(
880
- label="Type Your Answers Here",
881
- lines=20,
882
- placeholder="Type your answers using any of the formats shown above...",
883
- elem_classes="answer-input"
884
- )
885
 
886
- # Combined submit button
887
- with gr.Row():
888
- submit_btn = gr.Button(" Submit for Correction", variant="primary", size="lg")
889
-
890
- submit_status = gr.Textbox(
891
- label="Submission Status",
892
- interactive=False,
893
- lines=2
894
  )
 
 
 
 
 
 
 
 
 
 
895
 
896
  # Improved submission handler with better parsing
897
  def submit_answers(canvas_input, upload_input, typed_input):
 
698
  return f"Welcome, {session.student_name}!"
699
 
700
  student_name_input.change(update_student_name, student_name_input, None)
701
+
702
+ # Grade, Subject, Topic selection (shared across all tabs)
703
+ with gr.Group():
704
+ gr.Markdown("### Choose Your Topic")
705
+ with gr.Row():
706
+ grade_select = gr.Dropdown(
707
+ choices=["Primary 6", "Primary 7"],
708
+ label="Grade Level",
709
+ value="Primary 7"
710
+ )
711
+ subject_select = gr.Dropdown(
712
+ choices=["Mathematics", "English", "Social Studies", "Science"],
713
+ label="Subject",
714
+ value="Mathematics"
715
+ )
716
+ topic_select = gr.Dropdown(
717
+ label="Topic",
718
+ choices=syllabus_topics["Primary 7"]["Mathematics"],
719
+ value=syllabus_topics["Primary 7"]["Mathematics"][0]
720
+ )
721
+
722
+ # Update topics when grade or subject changes
723
+ def update_topics_shared(grade, subject):
724
+ topics = syllabus_topics.get(grade, {}).get(subject, [])
725
+ if not topics:
726
+ topics = ["General - " + subject]
727
+ return gr.Dropdown(choices=topics, value=topics[0])
728
+
729
+ grade_select.change(update_topics_shared, [grade_select, subject_select], topic_select)
730
+ subject_select.change(update_topics_shared, [grade_select, subject_select], topic_select)
731
+
732
  # Shared question display (placed below name and above the tabs to avoid large empty header)
733
  questions_display = gr.HTML(value="", elem_classes="question-display")
734
 
735
  with gr.Tabs():
736
  # ===== TAB 1: GENERATE QUESTIONS =====
737
  with gr.Tab("1️⃣ Generate Questions"):
738
+ gr.Markdown("### Step 1: Generate Practice Questions\n\nSet the Number of Questions (1–100) and click Generate.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
739
 
740
  with gr.Row():
741
  num_questions_input = gr.Slider(minimum=1, maximum=100, step=1, value=20, label="Number of Questions")
 
773
 
774
  generate_btn.click(
775
  fn=generate_and_display,
776
+ inputs=[grade_select, subject_select, topic_select, num_questions_input],
777
  outputs=[questions_display, questions_state, status_output]
778
  )
779
  # Download handler - returns file path for gr.DownloadButton
 
803
  gr.Markdown("### Step 2: Answer the Questions")
804
  gr.Markdown("Write out your working and answers. You can use any of the three methods below.")
805
 
806
+ gr.Markdown("**Note:** Questions are displayed above. Scroll up to see them while answering.")
807
+
808
  with gr.Row():
809
+ method_info = gr.Textbox(
810
+ label="How to Submit Answers",
811
+ value="Method 1: Draw/Write in canvas\nMethod 2: Upload photo of your written work\nMethod 3: Type your answers directly",
812
+ interactive=False,
813
+ lines=3
814
+ )
815
+
816
+ with gr.Tabs():
817
+ # Method 1: Draw
818
+ with gr.Tab("✏️ Draw Answers"):
819
+ canvas = gr.Sketchpad(
820
+ label="Draw or write your answers here",
821
+ type="pil",
822
+ height=500,
823
+ brush=gr.Brush(
824
+ colors=["#000000", "#0000FF", "#FF0000"],
825
+ default_size=4
826
+ )
827
+ )
828
+ canvas_status = gr.Textbox(
829
+ label="Canvas Status",
830
  interactive=False,
831
+ value="Ready to draw"
832
  )
833
 
834
+ # Method 2: Upload
835
+ with gr.Tab("📸 Upload Photo"):
836
+ upload_image = gr.Image(
837
+ label="Upload photo of your written work",
838
+ type="pil",
839
+ height=500
840
+ )
841
+ upload_status = gr.Textbox(
842
+ label="Upload Status",
843
+ interactive=False,
844
+ value="Ready to upload"
845
+ )
846
+
847
+ # Method 3: Type
848
+ with gr.Tab(" Type Answers"):
849
+ gr.Markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850
  ### 📝 Type Your Answers
851
 
852
  **Instructions:** Type each answer in the box below. Use one of these formats:
 
873
  Q2: Your answer here
874
  Q3: Your answer here
875
  ```
876
+ """)
 
 
 
 
 
 
 
877
 
878
+ typed_answers = gr.Textbox(
879
+ label="Type Your Answers Here",
880
+ lines=20,
881
+ placeholder="Type your answers using any of the formats shown above...",
882
+ elem_classes="answer-input"
 
 
 
883
  )
884
+
885
+ # Combined submit button
886
+ with gr.Row():
887
+ submit_btn = gr.Button(" Submit for Correction", variant="primary", size="lg")
888
+
889
+ submit_status = gr.Textbox(
890
+ label="Submission Status",
891
+ interactive=False,
892
+ lines=2
893
+ )
894
 
895
  # Improved submission handler with better parsing
896
  def submit_answers(canvas_input, upload_input, typed_input):