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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -330,43 +330,48 @@ def main_app():
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
- 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)
343
 
344
  with col_right:
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):
 
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
+ if "window_size" not in st.session_state:
336
+ st.session_state.window_size = 5 # The number of images to display at a time
337
 
338
  # Create left and right arrow buttons
339
  col_left, col_center, col_right = st.columns([1,8,1])
340
 
341
  with col_left:
342
  if st.button("◀️"):
343
+ st.session_state.current_window_start = max(0, st.session_state.current_window_start - st.session_state.window_size)
344
 
345
  with col_right:
346
  if st.button("▶️"):
347
+ st.session_state.current_window_start += st.session_state.window_size
348
 
349
  # Dynamically load images for the window
350
+ all_images = load_image_data(st.session_state.current_user, 0, 1000) # load all images
351
+
352
+ if all_images:
353
+ num_images = len(all_images)
354
+
355
+ # Calculate the range for images to display
356
+ start_index = st.session_state.current_window_start
357
+ end_index = min(start_index + st.session_state.window_size, num_images)
358
+
359
+ images_for_window = all_images[start_index:end_index]
360
 
361
+ # Setup columns for horizontal slider layout
362
+ num_images_to_display = len(images_for_window)
 
 
363
 
364
  cols = st.columns(num_images_to_display)
365
+ for i, image_data in enumerate(images_for_window):
 
 
 
 
366
  with cols[i]:
367
+ st.image(image_data['image_url'], width = 150)
368
+ st.write(f"**Prompt:** {image_data['prompt']}")
369
+ st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
370
+ st.write(f"**Realism:** {image_data['realism']}")
371
+ st.markdown("---")
372
+
373
  else:
374
+ st.write("No image generated yet!")
375
 
376
  # Logout button
377
  if st.button("Logout", on_click=logout_callback):