Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| story = "https://raw.githubusercontent.com/MK316/Spring2024/main/DLTESOL/project/story04.txt" | |
| questions = [ | |
| {"question": "1. What is the name of Mr. Elias's grandson?", "options": ["John", "Jamie", "Jason"], "answer": "Jamie"}, | |
| {"question": "2. What was the main job of Mr. Elias?", "options": ["Town Council member", "Ship Captain", "Lighthouse keeper"], "answer": "Lighthouse keeper"}, | |
| {"question": "3. Why did the town council want to replace the old lighthouse?", "options": ["It was too expensive to maintain", "It was too bright", "It was damaged by storms"], "answer": "It was too expensive to maintain"}, | |
| {"question": "4. What caused the failure of the new electronic navigation system?", "options": ["Poor installation", "Lack of electricity", "Severe weather conditions"], "answer": "Severe weather conditions"}, | |
| {"question": "5. Who carried the lantern to the top of the lighthouse during the storm??", "options": ["Mr. Elias", "A town council member", "Jamie"], "answer": "Jamie"}, | |
| {"question": "6. What did Jamie learn from the incident with the storm?", "options": ["The lighthouse is unnecessary", "Resilience and tradition are valuable", "Modern technology is always better"], "answer": "Resilience and tradition are valuable"}, | |
| {"question": "7. What did Jamie enjoy most about visiting the lighthouse?", "options": ["The view from the top", "Listening to his grandfather's stories", "Meeting the town council members"], "answer": "Listening to his grandfather's stories"} | |
| ] | |
| def quiz(*answers): | |
| score = 0 | |
| incorrect = [] | |
| for i, question in enumerate(questions): | |
| if answers[i] == question["answer"]: | |
| score += 1 | |
| else: | |
| incorrect.append(f"Question {i+1}: Correct answer is {question['answer']}") | |
| results = "\n".join(incorrect) | |
| return score, results | |
| story_display = gr.Markdown(story) | |
| inputs = [gr.Radio(label=q["question"], choices=q["options"]) for q in questions] | |
| outputs = [gr.Textbox(label="Score"), gr.Textbox(label="Incorrect Answers")] | |
| iface = gr.Interface(fn=quiz, inputs=inputs, outputs=outputs, description="The Lightkeeper's Lantern") | |
| iface.launch(share=True) |