hannah416 commited on
Commit
416914d
1 Parent(s): a7a5e56

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Define the comprehension questions
4
+ questions_mc = [
5
+ {"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"},
6
+ {"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"},
7
+ {"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"},
8
+ {"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"},
9
+ {"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"}
10
+ ]
11
+
12
+ questions_tf = [
13
+ {"question": "1. Tom loved exploring the outdoors and helping his parents in their garden.", "options": ["True", "False"], "answer": "True"},
14
+ {"question": "2. The peddler sold Tom an old toy.", "options": ["True", "False"], "answer": "False"},
15
+ {"question": "3. The seeds took a very long time to grow.", "options": ["True", "False"], "answer": "False"},
16
+ {"question": "4. Tom kept all the magic seeds for himself.", "options": ["True", "False"], "answer": "False"},
17
+ {"question": "5. The story highlights the importance of sharing and community.", "options": ["True", "False"], "answer": "True"}
18
+ ]
19
+
20
+ questions_sa = [
21
+ {"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."},
22
+ {"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."},
23
+ {"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."},
24
+ {"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."},
25
+ {"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."}
26
+ ]
27
+
28
+ vocabulary_questions = [
29
+ {"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"},
30
+ {"question": "2. Skeptical", "options": ["a) Believing without question", "b) Doubtful or questioning", "c) Full of energy", "d) Very colorful"], "answer": "b) Doubtful or questioning"},
31
+ {"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"},
32
+ {"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"},
33
+ {"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"}
34
+ ]
35
+
36
+ # Function to display the quiz and calculate the score
37
+ def quiz(*answers):
38
+ score = 0
39
+ incorrect = []
40
+ idx = 0
41
+
42
+ # Check multiple choice questions
43
+ for question in questions_mc:
44
+ if answers[idx] == question["answer"]:
45
+ score += 1
46
+ else:
47
+ incorrect.append(f"MC Question {idx + 1}: Correct answer is {question['answer']}")
48
+ idx += 1
49
+
50
+ # Check true/false questions
51
+ for question in questions_tf:
52
+ if answers[idx] == question["answer"]:
53
+ score += 1
54
+ else:
55
+ incorrect.append(f"TF Question {idx - len(questions_mc) + 1}: Correct answer is {question['answer']}")
56
+ idx += 1
57
+
58
+ # Check short answer questions
59
+ for question in questions_sa:
60
+ if answers[idx].strip().lower() == question["answer"].strip().lower():
61
+ score += 2
62
+ else:
63
+ incorrect.append(f"SA Question {idx - len(questions_mc) - len(questions_tf) + 1}: Correct answer is {question['answer']}")
64
+ idx += 1
65
+
66
+ # Check vocabulary questions
67
+ for question in vocabulary_questions:
68
+ if answers[idx] == question["answer"]:
69
+ score += 1
70
+ else:
71
+ incorrect.append(f"Vocab Question {idx - len(questions_mc) - len(questions_tf) - len(questions_sa) + 1}: Correct answer is {question['answer']}")
72
+ idx += 1
73
+
74
+ results = "\n".join(incorrect)
75
+ return score, results
76
+
77
+ # Inputs and outputs for Gradio interface
78
+ 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]
79
+ outputs = [gr.Textbox(label="Score"), gr.Textbox(label="Incorrect Answers")]
80
+
81
+ iface = gr.Interface(fn=quiz, inputs=inputs, outputs=outputs, description="Comprehension Quiz for 'The Peddler's Magic Seeds'")
82
+ iface.launch(share=True)