bgamazay commited on
Commit
04fc1b7
Β·
verified Β·
1 Parent(s): 76550bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -35,22 +35,18 @@ def load_data():
35
  )
36
  return pd.read_csv(local_path)
37
  except Exception:
38
- # If repo or file doesn't exist, create repo
39
  try:
40
  api.create_repo(repo_id=repo_id, repo_type="dataset", private=True, exist_ok=True)
41
  except Exception as e:
42
  st.error(f"Could not create storage repository: {e}")
43
-
44
  return pd.DataFrame(columns=["french", "context", "english", "active"])
45
 
46
  def save_data(df):
47
  api, token = get_api()
48
  repo_id = get_user_repo_id(api, token)
49
-
50
  csv_buffer = StringIO()
51
  df.to_csv(csv_buffer, index=False)
52
  csv_buffer.seek(0)
53
-
54
  try:
55
  api.upload_file(
56
  path_or_fileobj=csv_buffer.read().encode(),
@@ -78,7 +74,6 @@ if 'side_cycle_count' not in st.session_state:
78
  st.session_state['side_cycle_count'] = 0
79
 
80
  def set_page(page_name):
81
- # UPDATED: Just set state, let Streamlit handle the rerun automatically
82
  st.session_state['page'] = page_name
83
 
84
  def start_session():
@@ -101,7 +96,6 @@ def start_session():
101
  def next_card():
102
  st.session_state['current_card_idx'] += 1
103
  st.session_state['side_cycle_count'] = 0
104
-
105
  if st.session_state['current_card_idx'] >= len(st.session_state['deck']):
106
  st.balloons()
107
  st.success("Session Complete!")
@@ -134,13 +128,20 @@ def unarchive(df_idx):
134
 
135
  st.set_page_config(page_title="French Flashcards", page_icon="πŸ‡«πŸ‡·", layout="centered")
136
 
 
137
  st.markdown("""
138
  <style>
139
- .stButton>button {
140
- width: 100%;
141
- border-radius: 8px;
142
- height: 3em;
 
 
 
 
143
  }
 
 
144
  .card-container {
145
  padding: 40px;
146
  border-radius: 15px;
@@ -168,6 +169,7 @@ if st.session_state['page'] == 'home':
168
  st.title("πŸ‡«πŸ‡· French Practice")
169
  st.write(f"Total Cards: {len(st.session_state['df'])}")
170
 
 
171
  st.button("Start Session", on_click=start_session, type="primary")
172
  st.button("Add Card", on_click=lambda: set_page('add'))
173
  st.button("View Archive", on_click=lambda: set_page('archive'))
@@ -190,17 +192,16 @@ elif st.session_state['page'] == 'archive':
190
 
191
  df = st.session_state['df']
192
  if not df.empty:
193
- st.write("Below are your inactive cards. Click 'Unarchive' to restore.")
194
  archived = df[df['active'] == False]
195
  if archived.empty:
196
  st.info("Archive is empty.")
197
  else:
198
  for idx, row in archived.iterrows():
199
- col1, col2 = st.columns([4, 1])
200
- with col1:
201
- st.write(f"**{row['french']}** - {row['english']}")
202
- with col2:
203
- st.button("Unarchive", key=f"unarc_{idx}", on_click=unarchive, args=(idx,))
204
  else:
205
  st.write("No cards yet.")
206
 
@@ -231,17 +232,16 @@ elif st.session_state['page'] == 'play':
231
  </div>
232
  """, unsafe_allow_html=True)
233
 
234
- col1, col2 = st.columns([2, 1])
235
- with col1:
236
- def cycle_side():
237
- st.session_state['side_cycle_count'] += 1
238
- st.button("Flip / Next Side", on_click=cycle_side, type="primary")
239
-
240
- with col2:
241
- st.button("Next Card", on_click=next_card)
242
 
243
  st.divider()
244
- st.button("Archive this Card", on_click=archive_current_card, type="secondary")
245
  st.button("Quit Session", on_click=lambda: set_page('home'))
246
 
247
  else:
 
35
  )
36
  return pd.read_csv(local_path)
37
  except Exception:
 
38
  try:
39
  api.create_repo(repo_id=repo_id, repo_type="dataset", private=True, exist_ok=True)
40
  except Exception as e:
41
  st.error(f"Could not create storage repository: {e}")
 
42
  return pd.DataFrame(columns=["french", "context", "english", "active"])
43
 
44
  def save_data(df):
45
  api, token = get_api()
46
  repo_id = get_user_repo_id(api, token)
 
47
  csv_buffer = StringIO()
48
  df.to_csv(csv_buffer, index=False)
49
  csv_buffer.seek(0)
 
50
  try:
51
  api.upload_file(
52
  path_or_fileobj=csv_buffer.read().encode(),
 
74
  st.session_state['side_cycle_count'] = 0
75
 
76
  def set_page(page_name):
 
77
  st.session_state['page'] = page_name
78
 
79
  def start_session():
 
96
  def next_card():
97
  st.session_state['current_card_idx'] += 1
98
  st.session_state['side_cycle_count'] = 0
 
99
  if st.session_state['current_card_idx'] >= len(st.session_state['deck']):
100
  st.balloons()
101
  st.success("Session Complete!")
 
128
 
129
  st.set_page_config(page_title="French Flashcards", page_icon="πŸ‡«πŸ‡·", layout="centered")
130
 
131
+ # UPDATED CSS FOR FULL-WIDTH BUTTONS
132
  st.markdown("""
133
  <style>
134
+ /* Target all buttons within Streamlit */
135
+ div.stButton > button {
136
+ width: 100% !important; /* Force full width */
137
+ border-radius: 12px; /* Rounder corners */
138
+ height: 3.5em; /* Taller for easy tapping */
139
+ font-size: 18px; /* Larger text */
140
+ margin-top: 5px;
141
+ margin-bottom: 5px;
142
  }
143
+
144
+ /* Card Styling */
145
  .card-container {
146
  padding: 40px;
147
  border-radius: 15px;
 
169
  st.title("πŸ‡«πŸ‡· French Practice")
170
  st.write(f"Total Cards: {len(st.session_state['df'])}")
171
 
172
+ # Use columns to create spacing if needed, or just stack them
173
  st.button("Start Session", on_click=start_session, type="primary")
174
  st.button("Add Card", on_click=lambda: set_page('add'))
175
  st.button("View Archive", on_click=lambda: set_page('archive'))
 
192
 
193
  df = st.session_state['df']
194
  if not df.empty:
195
+ st.write("Below are your inactive cards.")
196
  archived = df[df['active'] == False]
197
  if archived.empty:
198
  st.info("Archive is empty.")
199
  else:
200
  for idx, row in archived.iterrows():
201
+ # Display cleaner rows
202
+ st.markdown(f"**{row['french']}** β€” *{row['english']}*")
203
+ st.button("Unarchive", key=f"unarc_{idx}", on_click=unarchive, args=(idx,))
204
+ st.divider()
 
205
  else:
206
  st.write("No cards yet.")
207
 
 
232
  </div>
233
  """, unsafe_allow_html=True)
234
 
235
+ # Primary Action (Flip) full width
236
+ def cycle_side():
237
+ st.session_state['side_cycle_count'] += 1
238
+ st.button("Flip / Next Side", on_click=cycle_side, type="primary")
239
+
240
+ # Secondary Action (Next Card) full width
241
+ st.button("Next Card", on_click=next_card)
 
242
 
243
  st.divider()
244
+ st.button("Archive this Card", on_click=archive_current_card)
245
  st.button("Quit Session", on_click=lambda: set_page('home'))
246
 
247
  else: