emvecchi commited on
Commit
52d0769
·
verified ·
1 Parent(s): 9a3e2d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -335,7 +335,8 @@ def render_dialogue(md_path: str,
335
 
336
 
337
  def render_rupture_markers_widget(index: int, choices: list[str]):
338
- """Dynamic list of (rupture_marker_i, line_a_i, line_b_i) with Add/Remove."""
 
339
  count_key = f"rupture_count_{index}"
340
  if count_key not in st.session_state:
341
  st.session_state[count_key] = 1 # start with one block
@@ -344,7 +345,6 @@ def render_rupture_markers_widget(index: int, choices: list[str]):
344
 
345
  st.markdown("**What rupture markers are found?** *(one per row; max 8)*")
346
 
347
- # render the i=1..count rows
348
  for i in range(1, count + 1):
349
  col1, col2, col3 = st.columns([3, 1, 1])
350
 
@@ -362,7 +362,6 @@ def render_rupture_markers_widget(index: int, choices: list[str]):
362
  if st.session_state.get(marker_key) is not None else 0
363
  )
364
 
365
- # line inputs (number or text)
366
  with col2:
367
  if RUPTURE_LINE_INPUT_TYPE == "number":
368
  st.number_input(f"Lines: {i} – from", min_value=1, step=1, key=a_key)
@@ -377,24 +376,28 @@ def render_rupture_markers_widget(index: int, choices: list[str]):
377
 
378
  st.markdown("---")
379
 
380
- # add/remove buttons
381
  a_col, b_col = st.columns([1, 1])
382
  with a_col:
383
- st.button(
384
  "➕ Add another rupture marker",
385
  key=f"add_rup_{index}",
386
  disabled=(count >= MAX_RUPTURE_MARKERS),
387
- on_click=lambda: st.session_state.__setitem__(count_key, min(MAX_RUPTURE_MARKERS, st.session_state[count_key] + 1))
388
  )
389
  with b_col:
390
- st.button(
391
  "➖ Remove last",
392
  key=f"remove_rup_{index}",
393
  disabled=(count <= 1),
394
- on_click=lambda: st.session_state.__setitem__(count_key, max(1, st.session_state[count_key] - 1))
395
  )
396
 
397
- # info text
 
 
 
 
 
 
398
  st.caption(f"{st.session_state[count_key]}/{MAX_RUPTURE_MARKERS} markers")
399
 
400
  #################################### Streamlit App ####################################
 
335
 
336
 
337
  def render_rupture_markers_widget(index: int, choices: list[str]):
338
+ """Dynamic list of (rupture_marker_i, line_a_i, line_b_i) with Add/Remove.
339
+ Works inside a st.form by using form_submit_button instead of callbacks."""
340
  count_key = f"rupture_count_{index}"
341
  if count_key not in st.session_state:
342
  st.session_state[count_key] = 1 # start with one block
 
345
 
346
  st.markdown("**What rupture markers are found?** *(one per row; max 8)*")
347
 
 
348
  for i in range(1, count + 1):
349
  col1, col2, col3 = st.columns([3, 1, 1])
350
 
 
362
  if st.session_state.get(marker_key) is not None else 0
363
  )
364
 
 
365
  with col2:
366
  if RUPTURE_LINE_INPUT_TYPE == "number":
367
  st.number_input(f"Lines: {i} – from", min_value=1, step=1, key=a_key)
 
376
 
377
  st.markdown("---")
378
 
379
+ # Use SUBMIT buttons (legal inside forms) to add/remove rows.
380
  a_col, b_col = st.columns([1, 1])
381
  with a_col:
382
+ add_clicked = st.form_submit_button(
383
  "➕ Add another rupture marker",
384
  key=f"add_rup_{index}",
385
  disabled=(count >= MAX_RUPTURE_MARKERS),
 
386
  )
387
  with b_col:
388
+ remove_clicked = st.form_submit_button(
389
  "➖ Remove last",
390
  key=f"remove_rup_{index}",
391
  disabled=(count <= 1),
 
392
  )
393
 
394
+ if add_clicked and count < MAX_RUPTURE_MARKERS:
395
+ st.session_state[count_key] = count + 1
396
+ st.rerun()
397
+ if remove_clicked and count > 1:
398
+ st.session_state[count_key] = count - 1
399
+ st.rerun()
400
+
401
  st.caption(f"{st.session_state[count_key]}/{MAX_RUPTURE_MARKERS} markers")
402
 
403
  #################################### Streamlit App ####################################