Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,14 +6,15 @@ questions = [
|
|
6 |
{"question": "What is the underlying message of the poem?", "options": ["The importance of making choices", "The beauty of nature", "The joy of youth", "The value of time"], "correct_option": 0}
|
7 |
]
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
def interactive_quiz(user_response=None, continue_quiz='yes', question_index=0):
|
10 |
output_messages = []
|
11 |
|
12 |
current_question = questions[question_index]
|
13 |
-
print(current_question)
|
14 |
-
output_messages.append(f"Question {question_index + 1}: {current_question['question']}")
|
15 |
-
for i, option in enumerate(current_question['options']):
|
16 |
-
output_messages.append(f"{i}. {option}")
|
17 |
|
18 |
if user_response is not None:
|
19 |
user_response = int(user_response)
|
@@ -27,12 +28,18 @@ def interactive_quiz(user_response=None, continue_quiz='yes', question_index=0):
|
|
27 |
question_index = 0
|
28 |
else:
|
29 |
question_index = (question_index + 1) % len(questions)
|
|
|
|
|
|
|
|
|
30 |
|
31 |
return "\n".join(output_messages), question_index
|
32 |
|
33 |
-
gr.Interface(
|
34 |
fn=interactive_quiz,
|
35 |
inputs=["text", "text", "number"],
|
36 |
outputs=["text", "number"],
|
37 |
live=True
|
38 |
-
)
|
|
|
|
|
|
6 |
{"question": "What is the underlying message of the poem?", "options": ["The importance of making choices", "The beauty of nature", "The joy of youth", "The value of time"], "correct_option": 0}
|
7 |
]
|
8 |
|
9 |
+
def get_first_question():
|
10 |
+
current_question = questions[0]
|
11 |
+
options = "\n".join([f"{idx}. {option}" for idx, option in enumerate(current_question['options'])])
|
12 |
+
return f"Question 1: {current_question['question']}\n{options}", 0
|
13 |
+
|
14 |
def interactive_quiz(user_response=None, continue_quiz='yes', question_index=0):
|
15 |
output_messages = []
|
16 |
|
17 |
current_question = questions[question_index]
|
|
|
|
|
|
|
|
|
18 |
|
19 |
if user_response is not None:
|
20 |
user_response = int(user_response)
|
|
|
28 |
question_index = 0
|
29 |
else:
|
30 |
question_index = (question_index + 1) % len(questions)
|
31 |
+
next_question = questions[question_index]
|
32 |
+
output_messages.append(f"\nQuestion {question_index + 1}: {next_question['question']}")
|
33 |
+
for i, option in enumerate(next_question['options']):
|
34 |
+
output_messages.append(f"{i}. {option}")
|
35 |
|
36 |
return "\n".join(output_messages), question_index
|
37 |
|
38 |
+
iface = gr.Interface(
|
39 |
fn=interactive_quiz,
|
40 |
inputs=["text", "text", "number"],
|
41 |
outputs=["text", "number"],
|
42 |
live=True
|
43 |
+
)
|
44 |
+
|
45 |
+
iface.launch()
|