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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -328,20 +328,32 @@ def main_app():
328
 
329
  st.header("Your Generated Images")
330
 
331
- # Load initial batch of images
332
- if st.session_state.images_data == [] or st.session_state.load_more_pressed == True:
333
- if st.session_state.load_more_pressed == True:
334
- st.session_state.start_index += st.session_state.batch_size
335
- st.session_state.images_data = [] # Clear the images data when load more is pressed
336
- # load all images if new login or load_more is pressed, also reset the flag
337
- st.session_state.images_data = load_image_data(st.session_state.current_user, st.session_state.start_index, st.session_state.batch_size)
338
- st.session_state.load_more_pressed = False
339
-
340
- # Setup columns for horizontal slider layout
341
- if st.session_state.images_data:
342
- num_images = len(st.session_state.images_data)
 
 
 
 
 
 
 
 
 
 
 
 
343
  cols = st.columns(num_images) # dynamically create columns according to data
344
- for i, image_data in enumerate(st.session_state.images_data):
345
  with cols[i]:
346
  st.image(image_data['image_url'], width = 150)
347
  st.write(f"**Prompt:** {image_data['prompt']}")
@@ -352,12 +364,6 @@ def main_app():
352
  st.write("No image generated yet!")
353
 
354
 
355
- # Load more button
356
- if st.button("Load More Images"):
357
- st.session_state.load_more_pressed = True
358
- # No loading here, we are now loading all the images when `load_more_pressed` flag is set to True
359
-
360
-
361
  # Logout button
362
  if st.button("Logout", on_click=logout_callback):
363
  pass
 
328
 
329
  st.header("Your Generated Images")
330
 
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)
343
+
344
+ with col_right:
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']}")
 
364
  st.write("No image generated yet!")
365
 
366
 
 
 
 
 
 
 
367
  # Logout button
368
  if st.button("Logout", on_click=logout_callback):
369
  pass