File size: 6,214 Bytes
416914d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import gradio as gr

# Define the comprehension questions
questions_mc = [
    {"question": "1. What was the main problem with Tom's family garden at the beginning of the story?", "options": ["a) It was too shady", "b) The soil was tough and dry", "c) It was overgrown with weeds", "d) The garden was too small"], "answer": "b) The soil was tough and dry"},
    {"question": "2. What caught Tom's attention in the peddler's cart?", "options": ["a) Pots and pans", "b) Cloths and toys", "c) Small packets of seeds tied with colorful ribbons", "d) Shiny jewelry"], "answer": "c) Small packets of seeds tied with colorful ribbons"},
    {"question": "3. How did the peddler describe the seeds to Tom?", "options": ["a) Ordinary seeds", "b) Expensive seeds", "c) Magic seeds", "d) Rare seeds"], "answer": "c) Magic seeds"},
    {"question": "4. What happened to Tom's garden after he planted the magic seeds?", "options": ["a) The plants didn't grow at all", "b) The plants grew slowly", "c) The plants grew quickly and vibrantly", "d) The plants wilted and died"], "answer": "c) The plants grew quickly and vibrantly"},
    {"question": "5. How did the village community react to Tom's garden?", "options": ["a) They ignored it", "b) They marveled at it and shared the seeds", "c) They tried to buy the garden", "d) They complained about it"], "answer": "b) They marveled at it and shared the seeds"}
]

questions_tf = [
    {"question": "1. Tom loved exploring the outdoors and helping his parents in their garden.", "options": ["True", "False"], "answer": "True"},
    {"question": "2. The peddler sold Tom an old toy.", "options": ["True", "False"], "answer": "False"},
    {"question": "3. The seeds took a very long time to grow.", "options": ["True", "False"], "answer": "False"},
    {"question": "4. Tom kept all the magic seeds for himself.", "options": ["True", "False"], "answer": "False"},
    {"question": "5. The story highlights the importance of sharing and community.", "options": ["True", "False"], "answer": "True"}
]

questions_sa = [
    {"question": "1. Why were Tom's parents skeptical about the magic seeds?", "answer": "They seemed too good to be true and they had never seen anything like them before."},
    {"question": "2. Describe the changes in Tom's garden after planting the magic seeds.", "answer": "Tom's garden transformed with tall, lush vegetables and beautiful flowers that were brighter and sweeter than any other plants in the village."},
    {"question": "3. How did Tom and his family contribute to the community after their garden flourished?", "answer": "They shared the magic seeds with their neighbors and taught them how to care for the plants, bringing the community together."},
    {"question": "4. What inspired Tom to become a peddler when he grew up?", "answer": "He wanted to spread the joy and wonder he experienced with the magic seeds to other villages."},
    {"question": "5. What is the main message of the story 'The Peddler's Magic Seeds'?", "answer": "Small beginnings can lead to great changes, and the importance of sharing and community."}
]

vocabulary_questions = [
    {"question": "1. Quaint", "options": ["a) Cheerful and full of energy", "b) Attractively unusual or old-fashioned", "c) Dry and lacking moisture", "d) Very large or important"], "answer": "b) Attractively unusual or old-fashioned"},
    {"question": "2. Skeptical", "options": ["a) Believing without question", "b) Doubtful or questioning", "c) Full of energy", "d) Very colorful"], "answer": "b) Doubtful or questioning"},
    {"question": "3. Prosper", "options": ["a) To fail or decline", "b) To grow strong and healthy", "c) To stay the same", "d) To become less important"], "answer": "b) To grow strong and healthy"},
    {"question": "4. Marvel", "options": ["a) To feel disappointed", "b) To be filled with wonder or astonishment", "c) To ignore completely", "d) To criticize harshly"], "answer": "b) To be filled with wonder or astonishment"},
    {"question": "5. Generously", "options": ["a) In a stingy manner", "b) In a selfish manner", "c) In a kind and giving way", "d) In a hurried way"], "answer": "c) In a kind and giving way"}
]

# Function to display the quiz and calculate the score
def quiz(*answers):
    score = 0
    incorrect = []
    idx = 0

    # Check multiple choice questions
    for question in questions_mc:
        if answers[idx] == question["answer"]:
            score += 1
        else:
            incorrect.append(f"MC Question {idx + 1}: Correct answer is {question['answer']}")
        idx += 1

    # Check true/false questions
    for question in questions_tf:
        if answers[idx] == question["answer"]:
            score += 1
        else:
            incorrect.append(f"TF Question {idx - len(questions_mc) + 1}: Correct answer is {question['answer']}")
        idx += 1

    # Check short answer questions
    for question in questions_sa:
        if answers[idx].strip().lower() == question["answer"].strip().lower():
            score += 2
        else:
            incorrect.append(f"SA Question {idx - len(questions_mc) - len(questions_tf) + 1}: Correct answer is {question['answer']}")
        idx += 1

    # Check vocabulary questions
    for question in vocabulary_questions:
        if answers[idx] == question["answer"]:
            score += 1
        else:
            incorrect.append(f"Vocab Question {idx - len(questions_mc) - len(questions_tf) - len(questions_sa) + 1}: Correct answer is {question['answer']}")
        idx += 1

    results = "\n".join(incorrect)
    return score, results

# Inputs and outputs for Gradio interface
inputs = [gr.Textbox(label="Enter your name")] + [gr.Radio(label=q["question"], choices=q["options"]) for q in questions_mc] + [gr.Radio(label=q["question"], choices=q["options"]) for q in questions_tf] + [gr.Textbox(label=q["question"]) for q in questions_sa] + [gr.Radio(label=q["question"], choices=q["options"]) for q in vocabulary_questions]
outputs = [gr.Textbox(label="Score"), gr.Textbox(label="Incorrect Answers")]

iface = gr.Interface(fn=quiz, inputs=inputs, outputs=outputs, description="Comprehension Quiz for 'The Peddler's Magic Seeds'")
iface.launch(share=True)