JustusI commited on
Commit
d72d7ad
·
verified ·
1 Parent(s): b6cc8f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -34
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
- # Optionally, randomize flashcard order on first run
58
- if "shuffled" not in st.session_state:
59
- random.shuffle(st.session_state.flashcards)
60
- st.session_state.shuffled = True
61
-
62
- current_card = st.session_state.flashcards[st.session_state.current_card]
63
- st.write(f"**Question:** {current_card.get('question', 'No question provided')}")
64
-
65
- # Button to reveal the answer
66
- if st.button("Show Answer"):
67
- st.session_state.show_answer = True
68
-
69
- # If answer is revealed, show answer and feedback options
70
- if st.session_state.show_answer:
71
- st.write(f"**Answer:** {current_card.get('answer', 'No answer provided')}")
72
- col1, col2 = st.columns(2)
73
- with col1:
74
- if st.button("Correct"):
75
- st.session_state.score += 1
76
- st.success("Correct!")
77
- with col2:
78
- if st.button("Wrong"):
79
- st.error("Incorrect!")
80
-
81
- # Navigation: if this is the last card, show final score; otherwise, go to next card.
 
82
  if st.button("Next Card"):
83
  st.session_state.current_card += 1
84
  st.session_state.show_answer = False
85
- #st.experimental_rerun()
86
 
87
- st.write(f"**Current Score:** {st.session_state.score}/{len(st.session_state.flashcards)}")
88
  else:
89
  st.info("No flashcards available. Please generate flashcards first.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
- # if st.button("Next Card"):
92
- # st.session_state.current_card = (st.session_state.current_card + 1) % len(st.session_state.flashcards)
93
- # st.session_state.show_answer = False
94
- # st.experimental_rerun()
95
 
96
- # st.write(f"**Current Score:** {st.session_state.score}/{len(st.session_state.flashcards)}")
97
- # else:
98
- # st.info("No flashcards available. Please generate flashcards first.")
 
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.")