Spaces:
Sleeping
Sleeping
PongsakornSET
commited on
Commit
•
a7c8b64
1
Parent(s):
ac006b7
Update app.py
Browse files
app.py
CHANGED
@@ -25,22 +25,26 @@ def generate_question():
|
|
25 |
# Initial configuration
|
26 |
if 'question_data' not in st.session_state:
|
27 |
st.session_state.question_data = generate_question()
|
|
|
28 |
|
29 |
thai_word, correct_answer, correct_part_of_speech, options = st.session_state.question_data
|
30 |
|
31 |
# Display question
|
32 |
st.write(f"คำว่า '{thai_word}' (ชนิดคำ: {correct_part_of_speech}) คือคำว่าอะไร?")
|
33 |
|
34 |
-
# Display answer options as buttons
|
35 |
selected_answer = st.radio("เลือกคำตอบของคุณ:", options)
|
36 |
|
37 |
-
#
|
38 |
-
if st.button("ตรวจคำตอบ"):
|
|
|
39 |
if selected_answer == correct_answer:
|
40 |
st.success("ถูกต้อง!")
|
41 |
else:
|
42 |
st.error(f"ผิด! คำตอบที่ถูกต้องคือ: {correct_answer}")
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
25 |
# Initial configuration
|
26 |
if 'question_data' not in st.session_state:
|
27 |
st.session_state.question_data = generate_question()
|
28 |
+
st.session_state.answered = False
|
29 |
|
30 |
thai_word, correct_answer, correct_part_of_speech, options = st.session_state.question_data
|
31 |
|
32 |
# Display question
|
33 |
st.write(f"คำว่า '{thai_word}' (ชนิดคำ: {correct_part_of_speech}) คือคำว่าอะไร?")
|
34 |
|
35 |
+
# Display answer options as radio buttons
|
36 |
selected_answer = st.radio("เลือกคำตอบของคุณ:", options)
|
37 |
|
38 |
+
# Check answer and show the result
|
39 |
+
if not st.session_state.answered and st.button("ตรวจคำตอบ"):
|
40 |
+
st.session_state.answered = True
|
41 |
if selected_answer == correct_answer:
|
42 |
st.success("ถูกต้อง!")
|
43 |
else:
|
44 |
st.error(f"ผิด! คำตอบที่ถูกต้องคือ: {correct_answer}")
|
45 |
|
46 |
+
# 'Next question' button to load a new question
|
47 |
+
if st.session_state.answered and st.button("คำถามถัดไป"):
|
48 |
+
st.session_state.question_data = generate_question()
|
49 |
+
st.session_state.answered = False
|
50 |
+
st.experimental_rerun()
|