Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
story = "https://raw.githubusercontent.com/MK316/Spring2024/main/Sample/storysample.txt"
|
4 |
+
|
5 |
+
cloze_questions = [
|
6 |
+
{"question": "Jamie ___ (love) to visit the lighthouse and was fascinated by the stories his grandfather told.", "answer": "loved"},
|
7 |
+
{"question": "One evening, as a fierce storm brewed, the council ___ (decide) to test their new electronic navigation system.", "answer": "decided"},
|
8 |
+
{"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"},
|
9 |
+
{"question": "Braving the howling wind and pelting rain, Jamie ______ (climb) the winding stairs of the lighthouse with the lantern.", "answer": "climbed"},
|
10 |
+
{"question": "All he ______ (can) do was hope it was enough.", "answer": "could"},
|
11 |
+
{"question": "Miraculously, the small light was ______ (see) by a nearby ship. ", "answer": "seen"},
|
12 |
+
{"question": "From that day on, the council ______ (reinstate) the old lighthouse, restoring it and even enhancing its light to ensure higher visibility. ", "answer": "reinstated"},
|
13 |
+
{"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"},
|
14 |
+
{"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"},
|
15 |
+
{"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"},
|
16 |
+
]
|
17 |
+
|
18 |
+
def cloze_quiz(name, *answers):
|
19 |
+
score = 0
|
20 |
+
results = []
|
21 |
+
for i, question in enumerate(cloze_questions):
|
22 |
+
if answers[i].strip().lower() == question["answer"].lower():
|
23 |
+
score += 1
|
24 |
+
results.append(f"Question {i+1}: Correct\n")
|
25 |
+
else:
|
26 |
+
results.append(f"Question {i+1}: Incorrect, the correct answer is: {question['answer']}\n")
|
27 |
+
result_text = f"* Name: {name}\n* Score: {score} out of {len(cloze_questions)}\n" + "\n".join(results)
|
28 |
+
|
29 |
+
return result_text
|
30 |
+
|
31 |
+
inputs = [gr.Textbox(label="Enter your name")] + [gr.Textbox(label=q["question"]) for q in cloze_questions]
|
32 |
+
outputs = [gr.Textbox(label="Results")]
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=cloze_quiz, inputs=inputs, outputs=outputs, description="The Lightkeeper's Lantern")
|
35 |
+
iface.launch(share=True)
|