import gradio as gr
story = "https://raw.githubusercontent.com/jmyoon7442/jmyoon7442/main/The%20Cave%20of%20Whisper.txt"
# Define the comprehension questions
questions = [
{"question": "1. What did they bring on their adventure?", "options": ["1) water, snacks, and a tent", "2) maps, books, and a compass", "3) flashlights, a compass, and a camera"], "answer": "3) flashlights, a compass, and a camera"},
{"question": "2. Who did read the message?", "options": ["1) Emma", "2) Liam", "3) Jake", "4) Mia"], "answer": "1) Emma"},
{"question": "3. What did the friends find inside the Cave of Whispers?", "options": ["1) A map to another treasure", "2) An old parchment", "3) A magical stone"], "answer": "2) An old parchment"},
{"question": "4. What did the message on the ancient parchment say?", "options" : ["1) Finders keepers, losers weepers.", "2) Gold is the measure of true wealth.", "3) True treasure lies in gold and gems only.", "4) True treasure lies not in gold but in the journey and the friendships forged along the way."], "answer": "4) True treasure lies not in gold but in the journey and the friendships forged along the way."},
{"question": "5. The four friends found an old map in a newly published book", "options": ["True", "False"], "answer": "False"},
{"question": "6. The four friends set the adventure in the morning.", "options": ["True", "False"], "answer": "False"},
{"question": "7. The four friends found a wooden chest in the Cave of Whispers, which contained golden coins and jewels.", "options": ["True", "False"], "answer": "True"},
{"question": "8. The four friends decided to sell the treasure and split the money.", "options": ["True", "False"], "answer": "True"},
{"question": "9. The friends used a GPS device and a smartphone to document their journey", "options": ["True", "False"], "answer": "False"}
]
# Function to display the story and ask questions
def quiz(name, *answers):
score = 0
incorrect = []
for i, question in enumerate(questions):
if answers[i] == question["answer"]:
score += 1
else:
incorrect.append(f"Question {i+1}")
incorrect_questions_text = ", ".join(incorrect)
result_text = f"* Name: {name}\n* Score: {score} out of {len(questions)}\n"
if incorrect:
result_text += f"Incorrect questions: {incorrect_questions_text}"
else:
result_text += "All answers are correct!"
return result_text
story_display = gr.Markdown(story)
inputs = [gr.Textbox(label="Enter your group name and names of your group members.")] + [gr.Radio(label=q["question"], choices=q["options"]) for q in questions]
outputs = [gr.Textbox(label="Results")]
# Adding the instruction in the description with larger and bolder text
instruction = """
[Group Activity - 5m]
Step 1. Choose the correct answer with your group members.
Step 2. Click the submit button and check your score. (If your answers are incorrect, try again.)
Step 3. Capture the screen showing the result and upload it to Padlet.
"""
iface = gr.Interface(fn=quiz, inputs=inputs, outputs=outputs, description=instruction)
iface.launch(share=True)