Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,45 +54,85 @@ with tab_gen:
|
|
| 54 |
with tab_practice:
|
| 55 |
st.header("Practice Flashcards")
|
| 56 |
if st.session_state.flashcards:
|
| 57 |
-
|
| 58 |
-
if
|
| 59 |
-
|
| 60 |
-
st.session_state.
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
st.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
if st.button("Next Card"):
|
| 83 |
st.session_state.current_card += 1
|
| 84 |
st.session_state.show_answer = False
|
| 85 |
-
|
| 86 |
|
| 87 |
-
st.write(f"**Current Score:** {st.session_state.score}/{
|
| 88 |
else:
|
| 89 |
st.info("No flashcards available. Please generate flashcards first.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 54 |
with tab_practice:
|
| 55 |
st.header("Practice Flashcards")
|
| 56 |
if st.session_state.flashcards:
|
| 57 |
+
total_cards = len(st.session_state.flashcards)
|
| 58 |
+
# Check if we've completed all flashcards
|
| 59 |
+
if st.session_state.current_card >= total_cards:
|
| 60 |
+
st.success(f"You've completed all flashcards! Final Score: {st.session_state.score} / {total_cards}")
|
| 61 |
+
st.info("Restart the practice session or generate new flashcards.")
|
| 62 |
+
else:
|
| 63 |
+
# Safe access: ensure current_card is valid
|
| 64 |
+
current_card = st.session_state.flashcards[st.session_state.current_card]
|
| 65 |
+
st.write(f"**Question:** {current_card.get('question', 'No question provided')}")
|
| 66 |
+
|
| 67 |
+
# Answer reveal button
|
| 68 |
+
if st.button("Show Answer"):
|
| 69 |
+
st.session_state.show_answer = True
|
| 70 |
+
|
| 71 |
+
# If answer is revealed, show it and provide feedback options
|
| 72 |
+
if st.session_state.show_answer:
|
| 73 |
+
st.write(f"**Answer:** {current_card.get('answer', 'No answer provided')}")
|
| 74 |
+
col1, col2 = st.columns(2)
|
| 75 |
+
with col1:
|
| 76 |
+
if st.button("Correct"):
|
| 77 |
+
st.session_state.score += 1
|
| 78 |
+
st.success("Correct!")
|
| 79 |
+
with col2:
|
| 80 |
+
if st.button("Wrong"):
|
| 81 |
+
st.error("Incorrect!")
|
| 82 |
+
|
| 83 |
if st.button("Next Card"):
|
| 84 |
st.session_state.current_card += 1
|
| 85 |
st.session_state.show_answer = False
|
| 86 |
+
st.rerun()
|
| 87 |
|
| 88 |
+
st.write(f"**Current Score:** {st.session_state.score}/{total_cards}")
|
| 89 |
else:
|
| 90 |
st.info("No flashcards available. Please generate flashcards first.")
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
# # --- Tab 2: Practice Flashcards ---
|
| 94 |
+
# with tab_practice:
|
| 95 |
+
# st.header("Practice Flashcards")
|
| 96 |
+
# if st.session_state.flashcards:
|
| 97 |
+
# # Optionally, randomize flashcard order on first run
|
| 98 |
+
# if "shuffled" not in st.session_state:
|
| 99 |
+
# random.shuffle(st.session_state.flashcards)
|
| 100 |
+
# st.session_state.shuffled = True
|
| 101 |
+
|
| 102 |
+
# current_card = st.session_state.flashcards[st.session_state.current_card]
|
| 103 |
+
# st.write(f"**Question:** {current_card.get('question', 'No question provided')}")
|
| 104 |
+
|
| 105 |
+
# # Button to reveal the answer
|
| 106 |
+
# if st.button("Show Answer"):
|
| 107 |
+
# st.session_state.show_answer = True
|
| 108 |
+
|
| 109 |
+
# # If answer is revealed, show answer and feedback options
|
| 110 |
+
# if st.session_state.show_answer:
|
| 111 |
+
# st.write(f"**Answer:** {current_card.get('answer', 'No answer provided')}")
|
| 112 |
+
# col1, col2 = st.columns(2)
|
| 113 |
+
# with col1:
|
| 114 |
+
# if st.button("Correct"):
|
| 115 |
+
# st.session_state.score += 1
|
| 116 |
+
# st.success("Correct!")
|
| 117 |
+
# with col2:
|
| 118 |
+
# if st.button("Wrong"):
|
| 119 |
+
# st.error("Incorrect!")
|
| 120 |
+
|
| 121 |
+
# # Navigation: if this is the last card, show final score; otherwise, go to next card.
|
| 122 |
+
# if st.button("Next Card"):
|
| 123 |
+
# st.session_state.current_card += 1
|
| 124 |
+
# st.session_state.show_answer = False
|
| 125 |
+
# #st.experimental_rerun()
|
| 126 |
+
|
| 127 |
+
# st.write(f"**Current Score:** {st.session_state.score}/{len(st.session_state.flashcards)}")
|
| 128 |
+
# else:
|
| 129 |
+
# st.info("No flashcards available. Please generate flashcards first.")
|
| 130 |
|
| 131 |
+
# # if st.button("Next Card"):
|
| 132 |
+
# # st.session_state.current_card = (st.session_state.current_card + 1) % len(st.session_state.flashcards)
|
| 133 |
+
# # st.session_state.show_answer = False
|
| 134 |
+
# # st.experimental_rerun()
|
| 135 |
|
| 136 |
+
# # st.write(f"**Current Score:** {st.session_state.score}/{len(st.session_state.flashcards)}")
|
| 137 |
+
# # else:
|
| 138 |
+
# # st.info("No flashcards available. Please generate flashcards first.")
|