File size: 2,627 Bytes
428fe58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

story = "https://raw.githubusercontent.com/MK316/Spring2024/main/Sample/storysample.txt"

cloze_questions = [
    {"question": "Jamie ___ (love) to visit the lighthouse and was fascinated by the stories his grandfather told.", "answer": "loved"},
    {"question": "One evening, as a fierce storm brewed, the council ___ (decide) to test their new electronic navigation system.", "answer": "decided"},
    {"question": "That night, with the storm at its peak and the new system in place, the unthinkable happened—the electronic system ___ (fail) due to the severe weather conditions", "answer": "failed"},
    {"question": "Braving the howling wind and pelting rain, Jamie ______ (climb) the winding stairs of the lighthouse with the lantern.", "answer": "climbed"},
    {"question": "All he ______ (can) do was hope it was enough.", "answer": "could"},
    {"question": "Miraculously, the small light was ______ (see) by a nearby ship. ", "answer": "seen"},
    {"question": "From that day on, the council ______ (reinstate) the old lighthouse, restoring it and even enhancing its light to ensure higher visibility. ", "answer": "reinstated"},
    {"question": "He maintained the tradition of the lighthouse while integrating modern technology responsibly, ensuring that the lighthouse ______ (continue) to be a beacon of safety and a symbol of the town’s enduring spirit.", "answer": "continued"},
    {"question": "The story of the lighthouse keeper’s lantern ___ (become) a cherished tale, reminding everyone that sometimes, the simplest solutions are the most effective in times of need.", "answer": "became"},
    {"question": "The lighthouse keeper, Mr. Elias, ___ (spend) many years ensuring the light never failed, keeping ships safe from the dangerous rocks below”", "answer": "had spent"},
]

def cloze_quiz(name, *answers):
    score = 0
    results = []
    for i, question in enumerate(cloze_questions):
        if answers[i].strip().lower() == question["answer"].lower():
            score += 1
            results.append(f"Question {i+1}: Correct\n")
        else:
            results.append(f"Question {i+1}: Incorrect, the correct answer is: {question['answer']}\n")
    result_text = f"* Name: {name}\n* Score: {score} out of {len(cloze_questions)}\n" + "\n".join(results)

    return result_text

inputs = [gr.Textbox(label="Enter your name")] + [gr.Textbox(label=q["question"]) for q in cloze_questions]
outputs = [gr.Textbox(label="Results")]

iface = gr.Interface(fn=cloze_quiz, inputs=inputs, outputs=outputs, description="The Lightkeeper's Lantern")
iface.launch(share=True)