Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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\
|
| 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=[
|
| 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 |
-
|
|
|
|
| 803 |
with gr.Row():
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
interactive=False,
|
| 814 |
-
|
| 815 |
)
|
| 816 |
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 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 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 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):
|