Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,17 @@ import json
|
|
| 3 |
import random
|
| 4 |
from fpdf import FPDF
|
| 5 |
|
| 6 |
-
# Load questions
|
| 7 |
with open("questions.json", "r") as f:
|
| 8 |
-
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
all_questions = question_bank["CLASS 4"] + question_bank["CLASS 5"]
|
| 12 |
-
|
| 13 |
-
# Pick 50 random questions for test
|
| 14 |
def get_test_questions():
|
| 15 |
return random.sample(all_questions, 50)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
# Function to grade test
|
| 18 |
def grade_test(student_name, father_name, roll_no, *answers):
|
| 19 |
questions = current_test_questions
|
|
@@ -43,9 +43,7 @@ def grade_test(student_name, father_name, roll_no, *answers):
|
|
| 43 |
return f"Score: {score} / {len(questions)}\nPercentage: {percentage:.2f}%", file_name
|
| 44 |
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
current_test_questions = get_test_questions()
|
| 48 |
-
|
| 49 |
student_inputs = [
|
| 50 |
gr.Textbox(label="Student Name", placeholder="Enter your name"),
|
| 51 |
gr.Textbox(label="Father's Name", placeholder="Enter father's name"),
|
|
@@ -59,6 +57,7 @@ for i, q in enumerate(current_test_questions):
|
|
| 59 |
gr.Radio(choices=q["options"], label=f"Q{i+1}. {q['question']}")
|
| 60 |
)
|
| 61 |
|
|
|
|
| 62 |
demo = gr.Interface(
|
| 63 |
fn=grade_test,
|
| 64 |
inputs=student_inputs + question_components,
|
|
|
|
| 3 |
import random
|
| 4 |
from fpdf import FPDF
|
| 5 |
|
| 6 |
+
# Load questions (flat list)
|
| 7 |
with open("questions.json", "r") as f:
|
| 8 |
+
all_questions = json.load(f)
|
| 9 |
|
| 10 |
+
# Select 50 random questions
|
|
|
|
|
|
|
|
|
|
| 11 |
def get_test_questions():
|
| 12 |
return random.sample(all_questions, 50)
|
| 13 |
|
| 14 |
+
# Store current test questions globally
|
| 15 |
+
current_test_questions = get_test_questions()
|
| 16 |
+
|
| 17 |
# Function to grade test
|
| 18 |
def grade_test(student_name, father_name, roll_no, *answers):
|
| 19 |
questions = current_test_questions
|
|
|
|
| 43 |
return f"Score: {score} / {len(questions)}\nPercentage: {percentage:.2f}%", file_name
|
| 44 |
|
| 45 |
|
| 46 |
+
# Input fields for student info
|
|
|
|
|
|
|
| 47 |
student_inputs = [
|
| 48 |
gr.Textbox(label="Student Name", placeholder="Enter your name"),
|
| 49 |
gr.Textbox(label="Father's Name", placeholder="Enter father's name"),
|
|
|
|
| 57 |
gr.Radio(choices=q["options"], label=f"Q{i+1}. {q['question']}")
|
| 58 |
)
|
| 59 |
|
| 60 |
+
# Build Gradio interface
|
| 61 |
demo = gr.Interface(
|
| 62 |
fn=grade_test,
|
| 63 |
inputs=student_inputs + question_components,
|