salomonsky commited on
Commit
db53266
1 Parent(s): f00c319

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -119,28 +119,26 @@ async def generate_variations(prompt, num_variants, use_enhanced, style):
119
  def image_viewer():
120
  images = list_saved_images()
121
  if images:
122
- if 'current_image_index' not in st.session_state:
123
- st.session_state['current_image_index'] = 0
124
-
125
- current_index = st.session_state['current_image_index']
126
- image_file = images[current_index]
127
- st.image(str(image_file), use_column_width=True, caption=image_file.name)
128
-
129
- st.write("### Galería")
130
- thumbnail_cols = st.columns(len(images))
131
- for i, image_file in enumerate(images):
132
- with thumbnail_cols[i]:
133
- if st.button("", key=f"thumb_{i}"):
 
 
 
 
 
 
134
  st.session_state['current_image_index'] = i
135
- st.image(str(image_file), width=100, caption=image_file.name)
136
-
137
- col1, col2, col3 = st.columns([1, 2, 1])
138
- with col1:
139
- if st.button("⬅️", key="prev_image"):
140
- st.session_state['current_image_index'] = (current_index - 1) % len(images)
141
- with col3:
142
- if st.button("➡️", key="next_image"):
143
- st.session_state['current_image_index'] = (current_index + 1) % len(images)
144
  else:
145
  st.info("No hay imágenes guardadas.")
146
 
 
119
  def image_viewer():
120
  images = list_saved_images()
121
  if images:
122
+ st.write("### Galería de Imágenes")
123
+ thumbnails = []
124
+
125
+ for image_file in images:
126
+ with Image.open(image_file) as img:
127
+ min_side = min(img.size)
128
+ cropped_img = img.crop(((img.width - min_side) // 2, (img.height - min_side) // 2,
129
+ (img.width + min_side) // 2, (img.height + min_side) // 2))
130
+ thumbnail = cropped_img.resize((100, 100))
131
+ thumbnails.append((image_file.name, thumbnail))
132
+
133
+ cols = st.columns(8)
134
+
135
+ for i, (name, thumbnail) in enumerate(thumbnails):
136
+ col = cols[i % 8]
137
+ with col:
138
+ st.image(thumbnail, use_column_width=False, width=100, caption=name)
139
+ if st.button("Ver", key=f"view_{i}"):
140
  st.session_state['current_image_index'] = i
141
+ st.image(str(images[i]), caption=name)
 
 
 
 
 
 
 
 
142
  else:
143
  st.info("No hay imágenes guardadas.")
144