bgamazay commited on
Commit
6be4983
·
verified ·
1 Parent(s): 7f0a775

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -50
app.py CHANGED
@@ -136,9 +136,10 @@ def unarchive(df_idx):
136
 
137
  st.set_page_config(page_title="French Flashcards", page_icon="🇫🇷", layout="centered")
138
 
 
139
  st.markdown("""
140
  <style>
141
- /* 1. General Button Styling (The navigation buttons) */
142
  .stButton > button {
143
  width: 100% !important;
144
  border-radius: 12px;
@@ -147,43 +148,10 @@ st.markdown("""
147
  margin-bottom: 8px;
148
  }
149
 
150
- /* 2. THE CARD BUTTON (Specific targeting)
151
- We will use a key to target the card button specifically if possible,
152
- but Streamlit makes this hard. We will use a CSS hack on the 'primary' type
153
- combined with a large height.
154
- */
155
-
156
- div[data-testid="stButton"] button[kind="primary"] {
157
- height: 300px !important; /* Make the card tall */
158
- background-color: white !important;
159
- color: #1f2937 !important;
160
- border: 2px solid #e5e7eb !important;
161
- box-shadow: 0 4px 6px rgba(0,0,0,0.1) !important;
162
- white-space: pre-wrap !important; /* Allow text wrapping */
163
- display: flex;
164
- flex-direction: column;
165
- align-items: center;
166
- justify-content: center;
167
- transition: transform 0.1s;
168
- }
169
-
170
- div[data-testid="stButton"] button[kind="primary"]:active {
171
- transform: scale(0.98);
172
- border-color: #3b82f6 !important;
173
- }
174
-
175
- div[data-testid="stButton"] button[kind="primary"] p {
176
- font-size: 28px !important;
177
- font-weight: bold !important;
178
- }
179
-
180
- /* Small labels on the card */
181
- .card-hint {
182
- font-size: 14px;
183
- color: #9ca3af;
184
- margin-bottom: 10px;
185
- text-transform: uppercase;
186
- letter-spacing: 2px;
187
  }
188
  </style>
189
  """, unsafe_allow_html=True)
@@ -206,12 +174,11 @@ elif st.session_state['page'] == 'add':
206
  if submitted and fr and en:
207
  add_card(fr, ctx, en)
208
 
209
- st.button("Back", on_click=lambda: set_page('home'), use_container_width=True)
210
 
211
  elif st.session_state['page'] == 'edit':
212
  st.title("Edit Card")
213
 
214
- # Get current card data
215
  deck_idx = st.session_state['current_card_idx']
216
  df_idx = st.session_state['deck'][deck_idx]
217
  row = st.session_state['df'].iloc[df_idx]
@@ -225,11 +192,11 @@ elif st.session_state['page'] == 'edit':
225
  if saved:
226
  save_edited_card(df_idx, new_fr, new_ctx, new_en)
227
 
228
- st.button("Cancel", on_click=lambda: set_page('play'), use_container_width=True)
229
 
230
  elif st.session_state['page'] == 'archive':
231
  st.title("Archive")
232
- st.button("Back", on_click=lambda: set_page('home'), use_container_width=True)
233
 
234
  df = st.session_state['df']
235
  if not df.empty:
@@ -252,27 +219,66 @@ elif st.session_state['page'] == 'play':
252
  df_idx = st.session_state['deck'][deck_idx]
253
  card = st.session_state['df'].iloc[df_idx]
254
 
 
255
  cycle_map = {0: 'French', 1: 'Context', 2: 'English', 3: 'Context'}
256
  current_side_idx = st.session_state['side_cycle_count'] % 4
257
  side_name = cycle_map[current_side_idx]
258
 
259
  content = ""
260
- if side_name == 'French': content = card['french']
261
- elif side_name == 'Context': content = card['context']
262
- elif side_name == 'English': content = card['english']
 
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  progress = (deck_idx + 1) / len(st.session_state['deck'])
265
  st.progress(progress)
266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  # --- THE CLICKABLE CARD ---
268
  def cycle_side():
269
  st.session_state['side_cycle_count'] += 1
270
 
271
- # We construct the label with newlines to center the content visually
272
- # Note: The CSS above targets this button because we use type="primary"
273
- label_text = f"{side_name}\n\n{content}"
274
-
275
- st.button(label_text, on_click=cycle_side, type="primary", use_container_width=True)
276
 
277
  # --- NAVIGATION ---
278
  st.button("Next Card", on_click=next_card, use_container_width=True)
 
136
 
137
  st.set_page_config(page_title="French Flashcards", page_icon="🇫🇷", layout="centered")
138
 
139
+ # --- GLOBAL CSS ---
140
  st.markdown("""
141
  <style>
142
+ /* 1. General Button Styling */
143
  .stButton > button {
144
  width: 100% !important;
145
  border-radius: 12px;
 
148
  margin-bottom: 8px;
149
  }
150
 
151
+ /* 2. BIGGER INPUT TEXT (For Mobile Editing) */
152
+ .stTextInput input, .stTextArea textarea {
153
+ font-size: 20px !important; /* Bigger font for inputs */
154
+ line-height: 1.5 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  }
156
  </style>
157
  """, unsafe_allow_html=True)
 
174
  if submitted and fr and en:
175
  add_card(fr, ctx, en)
176
 
177
+ st.button("Return", on_click=lambda: set_page('home'), use_container_width=True)
178
 
179
  elif st.session_state['page'] == 'edit':
180
  st.title("Edit Card")
181
 
 
182
  deck_idx = st.session_state['current_card_idx']
183
  df_idx = st.session_state['deck'][deck_idx]
184
  row = st.session_state['df'].iloc[df_idx]
 
192
  if saved:
193
  save_edited_card(df_idx, new_fr, new_ctx, new_en)
194
 
195
+ st.button("Return", on_click=lambda: set_page('play'), use_container_width=True)
196
 
197
  elif st.session_state['page'] == 'archive':
198
  st.title("Archive")
199
+ st.button("Return", on_click=lambda: set_page('home'), use_container_width=True)
200
 
201
  df = st.session_state['df']
202
  if not df.empty:
 
219
  df_idx = st.session_state['deck'][deck_idx]
220
  card = st.session_state['df'].iloc[df_idx]
221
 
222
+ # Cycle: 0:Fr, 1:Ctx, 2:En, 3:Ctx
223
  cycle_map = {0: 'French', 1: 'Context', 2: 'English', 3: 'Context'}
224
  current_side_idx = st.session_state['side_cycle_count'] % 4
225
  side_name = cycle_map[current_side_idx]
226
 
227
  content = ""
228
+ # Defaults
229
+ card_bg = "#ffffff"
230
+ card_text = "#000000"
231
+ card_font_size = "32px"
232
 
233
+ if side_name == 'French':
234
+ content = card['french']
235
+ card_bg = "#ffffff" # White
236
+ card_text = "#1f2937" # Dark Grey
237
+
238
+ elif side_name == 'Context':
239
+ content = card['context']
240
+ card_bg = "#3b82f6" # Blue
241
+ card_text = "#ffffff" # White
242
+ card_font_size = "20px" # Smaller for long text
243
+
244
+ elif side_name == 'English':
245
+ content = card['english']
246
+ card_bg = "#ef4444" # Red
247
+ card_text = "#ffffff" # White
248
+
249
  progress = (deck_idx + 1) / len(st.session_state['deck'])
250
  st.progress(progress)
251
 
252
+ # --- DYNAMIC STYLE INJECTION ---
253
+ # This overwrites the 'Primary' button style JUST for this render loop
254
+ st.markdown(f"""
255
+ <style>
256
+ div[data-testid="stButton"] button[kind="primary"] {{
257
+ height: 300px !important;
258
+ background-color: {card_bg} !important;
259
+ color: {card_text} !important;
260
+ border: 2px solid #e5e7eb !important;
261
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1) !important;
262
+ white-space: pre-wrap !important;
263
+ display: flex;
264
+ flex-direction: column;
265
+ align-items: center;
266
+ justify-content: center;
267
+ transition: transform 0.1s;
268
+ }}
269
+ div[data-testid="stButton"] button[kind="primary"] p {{
270
+ font-size: {card_font_size} !important;
271
+ font-weight: bold !important;
272
+ }}
273
+ </style>
274
+ """, unsafe_allow_html=True)
275
+
276
  # --- THE CLICKABLE CARD ---
277
  def cycle_side():
278
  st.session_state['side_cycle_count'] += 1
279
 
280
+ # Just the content, no label
281
+ st.button(content, on_click=cycle_side, type="primary", use_container_width=True)
 
 
 
282
 
283
  # --- NAVIGATION ---
284
  st.button("Next Card", on_click=next_card, use_container_width=True)