artintel235 commited on
Commit
b6f4a85
·
verified ·
1 Parent(s): 3f0f169

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -331,12 +331,12 @@ def main_app():
331
  # Initialize the current window, if it doesn't exist in session state
332
  if "current_window_start" not in st.session_state:
333
  st.session_state.current_window_start = 0
334
-
 
335
 
336
  # Create left and right arrow buttons
337
  col_left, col_center, col_right = st.columns([1,8,1])
338
 
339
-
340
  with col_left:
341
  if st.button("◀️"):
342
  st.session_state.current_window_start = max(0, st.session_state.current_window_start - st.session_state.batch_size)
@@ -345,25 +345,29 @@ def main_app():
345
  if st.button("▶️"):
346
  st.session_state.current_window_start += st.session_state.batch_size
347
 
348
-
349
  # Dynamically load images for the window
350
  images_for_window = load_image_data(st.session_state.current_user, st.session_state.current_window_start, st.session_state.batch_size*3) # Load three batch sizes to cover sliding window
351
 
352
- # Setup columns for horizontal slider layout
353
  if images_for_window:
354
  num_images = len(images_for_window)
355
- cols = st.columns(num_images) # dynamically create columns according to data
356
- for i, image_data in enumerate(images_for_window):
357
- with cols[i]:
358
- st.image(image_data['image_url'], width = 150)
359
- st.write(f"**Prompt:** {image_data['prompt']}")
360
- st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
361
- st.write(f"**Realism:** {image_data['realism']}")
362
- st.markdown("---")
 
 
 
 
 
 
363
  else:
364
  st.write("No image generated yet!")
365
 
366
-
367
  # Logout button
368
  if st.button("Logout", on_click=logout_callback):
369
  pass
 
331
  # Initialize the current window, if it doesn't exist in session state
332
  if "current_window_start" not in st.session_state:
333
  st.session_state.current_window_start = 0
334
+ if "max_images_to_display" not in st.session_state:
335
+ st.session_state.max_images_to_display = 5 #maximum number of images to display
336
 
337
  # Create left and right arrow buttons
338
  col_left, col_center, col_right = st.columns([1,8,1])
339
 
 
340
  with col_left:
341
  if st.button("◀️"):
342
  st.session_state.current_window_start = max(0, st.session_state.current_window_start - st.session_state.batch_size)
 
345
  if st.button("▶️"):
346
  st.session_state.current_window_start += st.session_state.batch_size
347
 
 
348
  # Dynamically load images for the window
349
  images_for_window = load_image_data(st.session_state.current_user, st.session_state.current_window_start, st.session_state.batch_size*3) # Load three batch sizes to cover sliding window
350
 
351
+ # Setup columns for horizontal slider layout
352
  if images_for_window:
353
  num_images = len(images_for_window)
354
+ num_images_to_display = min(st.session_state.max_images_to_display, num_images) # To limit max images to display
355
+
356
+ cols = st.columns(num_images_to_display)
357
+
358
+ start_index = max(0, num_images - num_images_to_display)
359
+
360
+ for i, image_data in enumerate(images_for_window[start_index:]):
361
+ if i < num_images_to_display:
362
+ with cols[i]:
363
+ st.image(image_data['image_url'], width = 150)
364
+ st.write(f"**Prompt:** {image_data['prompt']}")
365
+ st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
366
+ st.write(f"**Realism:** {image_data['realism']}")
367
+ st.markdown("---")
368
  else:
369
  st.write("No image generated yet!")
370
 
 
371
  # Logout button
372
  if st.button("Logout", on_click=logout_callback):
373
  pass