Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,29 +9,21 @@ def load_data():
|
|
| 9 |
df = load_data()
|
| 10 |
|
| 11 |
properties = ['Voicing', 'Place', 'Centrality', 'Oro-nasal', 'Manner']
|
| 12 |
-
|
| 13 |
|
| 14 |
def generate_question():
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return "All IPA symbols have been used. Quiz will restart.", "", 0
|
| 18 |
-
|
| 19 |
-
# Generate a unique pair that has not been used yet
|
| 20 |
-
while True:
|
| 21 |
current_ipa = df.sample(1).iloc[0]
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
question = f"IPA Symbol: {current_ipa['IPA']}\nWhat is the {property_name.lower()} of this IPA symbol?"
|
| 29 |
-
answer = current_ipa[property_name].lower() # Convert answer to lowercase
|
| 30 |
-
return question, answer, current_property_index
|
| 31 |
|
| 32 |
def quiz_function(user_answer, score, trials, correct_answer):
|
| 33 |
-
|
| 34 |
-
if user_answer == correct_answer:
|
| 35 |
score[0] += 1
|
| 36 |
result = f"Correct! The answer was '{correct_answer}'."
|
| 37 |
else:
|
|
@@ -54,10 +46,8 @@ def gradio_interface():
|
|
| 54 |
def submit_answer(user_answer):
|
| 55 |
result = quiz_function(user_answer, score, trials, question_info['answer'])
|
| 56 |
new_question, new_answer, new_property_index = generate_question()
|
| 57 |
-
if new_question == "All IPA symbols have been used. Quiz will restart.":
|
| 58 |
-
used_pairs.clear() # Clear the set to restart the quiz
|
| 59 |
question_info.update({'question': new_question, 'answer': new_answer, 'property_index': new_property_index})
|
| 60 |
-
return result,
|
| 61 |
|
| 62 |
def quit_quiz():
|
| 63 |
# Use the user's name stored in user_name list
|
|
@@ -74,7 +64,7 @@ def gradio_interface():
|
|
| 74 |
quit_button = gr.Button("Quit")
|
| 75 |
|
| 76 |
start_button.click(fn=start_quiz, inputs=[name_input], outputs=[question_label])
|
| 77 |
-
submit_button.click(fn=submit_answer, inputs=[answer_input], outputs=[output_label,
|
| 78 |
quit_button.click(fn=quit_quiz, outputs=[output_label])
|
| 79 |
|
| 80 |
return app
|
|
|
|
| 9 |
df = load_data()
|
| 10 |
|
| 11 |
properties = ['Voicing', 'Place', 'Centrality', 'Oro-nasal', 'Manner']
|
| 12 |
+
used_ipa_symbols = []
|
| 13 |
|
| 14 |
def generate_question():
|
| 15 |
+
current_ipa = df.sample(1).iloc[0]
|
| 16 |
+
while current_ipa['IPA'] in used_ipa_symbols:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
current_ipa = df.sample(1).iloc[0]
|
| 18 |
+
used_ipa_symbols.append(current_ipa['IPA'])
|
| 19 |
+
current_property_index = random.randint(0, len(properties) - 1)
|
| 20 |
+
property_name = properties[current_property_index]
|
| 21 |
+
question = f"IPA Symbol: {current_ipa['IPA']}\nWhat is the {property_name.lower()} of this IPA symbol?"
|
| 22 |
+
answer = current_ipa[property_name].lower()
|
| 23 |
+
return question, answer, current_property_index
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def quiz_function(user_answer, score, trials, correct_answer):
|
| 26 |
+
if user_answer.lower() == correct_answer:
|
|
|
|
| 27 |
score[0] += 1
|
| 28 |
result = f"Correct! The answer was '{correct_answer}'."
|
| 29 |
else:
|
|
|
|
| 46 |
def submit_answer(user_answer):
|
| 47 |
result = quiz_function(user_answer, score, trials, question_info['answer'])
|
| 48 |
new_question, new_answer, new_property_index = generate_question()
|
|
|
|
|
|
|
| 49 |
question_info.update({'question': new_question, 'answer': new_answer, 'property_index': new_property_index})
|
| 50 |
+
return result, new_question
|
| 51 |
|
| 52 |
def quit_quiz():
|
| 53 |
# Use the user's name stored in user_name list
|
|
|
|
| 64 |
quit_button = gr.Button("Quit")
|
| 65 |
|
| 66 |
start_button.click(fn=start_quiz, inputs=[name_input], outputs=[question_label])
|
| 67 |
+
submit_button.click(fn=submit_answer, inputs=[answer_input], outputs=[output_label, question_label])
|
| 68 |
quit_button.click(fn=quit_quiz, outputs=[output_label])
|
| 69 |
|
| 70 |
return app
|