assistanttttttt commited on
Commit
e050d47
·
1 Parent(s): ceb007a

Fix syntax and deduplicate gallery loader

Browse files
Files changed (1) hide show
  1. ui/layout.py +15 -16
ui/layout.py CHANGED
@@ -10,22 +10,21 @@ def build_ui(event_handler_function):
10
  ui_components = {}
11
 
12
  # Helper function to load thumbnails from the output folder.
13
- + # Helper function to load thumbnails from the output folder.
14
- + # It returns a **deduplicated** list of absolute image file paths.
15
- + # Using a set ensures that even if the same filename appears multiple
16
- + # times (e.g., due to accidental duplicate saves), the Gallery tab will
17
- + # only display each image once.
18
- + def load_gallery_images():
19
- + output_dir = os.path.abspath(OUTPUT_DIR)
20
- + if not os.path.isdir(output_dir):
21
- + return []
22
- + # Use a set to collect unique absolute paths.
23
- + image_path_set = set()
24
- + for fname in sorted(os.listdir(output_dir)):
25
- + if fname.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
26
- + image_path_set.add(os.path.join(output_dir, fname))
27
- + # Convert back to a sorted list for deterministic ordering.
28
- + return sorted(image_path_set)
29
 
30
  # All UI components, including tabs, must be created inside the same Gradio Blocks context.
31
  with gr.Blocks() as demo:
 
10
  ui_components = {}
11
 
12
  # Helper function to load thumbnails from the output folder.
13
+ # It returns a **deduplicated** list of absolute image file paths.
14
+ # Using a set ensures that even if the same filename appears multiple
15
+ # times (e.g., due to accidental duplicate saves), the Gallery tab will
16
+ # only display each image once.
17
+ def load_gallery_images():
18
+ output_dir = os.path.abspath(OUTPUT_DIR)
19
+ if not os.path.isdir(output_dir):
20
+ return []
21
+ # Use a set to collect unique absolute paths.
22
+ image_path_set = set()
23
+ for fname in sorted(os.listdir(output_dir)):
24
+ if fname.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
25
+ image_path_set.add(os.path.join(output_dir, fname))
26
+ # Convert back to a sorted list for deterministic ordering.
27
+ return sorted(image_path_set)
 
28
 
29
  # All UI components, including tabs, must be created inside the same Gradio Blocks context.
30
  with gr.Blocks() as demo: