awacke1 commited on
Commit
3a3e5ac
·
verified ·
1 Parent(s): 790f40d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -63,6 +63,8 @@ if 'asset_checkboxes' not in st.session_state:
63
  st.session_state['asset_checkboxes'] = {}
64
  if 'downloaded_pdfs' not in st.session_state:
65
  st.session_state['downloaded_pdfs'] = {}
 
 
66
 
67
  @dataclass
68
  class ModelConfig:
@@ -531,6 +533,8 @@ def update_gallery():
531
  cols = st.sidebar.columns(2)
532
  for idx, file in enumerate(all_files[:gallery_size * 2]):
533
  with cols[idx % 2]:
 
 
534
  if file.endswith('.png'):
535
  st.image(Image.open(file), caption=os.path.basename(file), use_container_width=True)
536
  else:
@@ -539,7 +543,7 @@ def update_gallery():
539
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
540
  st.image(img, caption=os.path.basename(file), use_container_width=True)
541
  doc.close()
542
- checkbox_key = f"asset_{file}_{idx}" # Unique key with index
543
  st.session_state['asset_checkboxes'][file] = st.checkbox(
544
  "Use for SFT/Input",
545
  value=st.session_state['asset_checkboxes'].get(file, False),
@@ -547,7 +551,7 @@ def update_gallery():
547
  )
548
  mime_type = "image/png" if file.endswith('.png') else "application/pdf"
549
  st.markdown(get_download_link(file, mime_type, "Snag It! 📥"), unsafe_allow_html=True)
550
- if st.button("Zap It! 🗑️", key=f"delete_{file}_{idx}"): # Unique key with index
551
  os.remove(file)
552
  if file in st.session_state['asset_checkboxes']:
553
  del st.session_state['asset_checkboxes'][file]
 
63
  st.session_state['asset_checkboxes'] = {}
64
  if 'downloaded_pdfs' not in st.session_state:
65
  st.session_state['downloaded_pdfs'] = {}
66
+ if 'unique_counter' not in st.session_state:
67
+ st.session_state['unique_counter'] = 0 # For generating unique keys
68
 
69
  @dataclass
70
  class ModelConfig:
 
533
  cols = st.sidebar.columns(2)
534
  for idx, file in enumerate(all_files[:gallery_size * 2]):
535
  with cols[idx % 2]:
536
+ st.session_state['unique_counter'] += 1 # Increment counter for uniqueness
537
+ unique_id = st.session_state['unique_counter']
538
  if file.endswith('.png'):
539
  st.image(Image.open(file), caption=os.path.basename(file), use_container_width=True)
540
  else:
 
543
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
544
  st.image(img, caption=os.path.basename(file), use_container_width=True)
545
  doc.close()
546
+ checkbox_key = f"asset_{file}_{unique_id}" # Unique key with counter
547
  st.session_state['asset_checkboxes'][file] = st.checkbox(
548
  "Use for SFT/Input",
549
  value=st.session_state['asset_checkboxes'].get(file, False),
 
551
  )
552
  mime_type = "image/png" if file.endswith('.png') else "application/pdf"
553
  st.markdown(get_download_link(file, mime_type, "Snag It! 📥"), unsafe_allow_html=True)
554
+ if st.button("Zap It! 🗑️", key=f"delete_{file}_{unique_id}"): # Unique key with counter
555
  os.remove(file)
556
  if file in st.session_state['asset_checkboxes']:
557
  del st.session_state['asset_checkboxes'][file]