Commit ·
ceb007a
1
Parent(s): b0c0c9b
Deduplicate images in load_gallery_images to prevent duplicate thumbnails
Browse files- ui/layout.py +16 -9
ui/layout.py
CHANGED
|
@@ -10,15 +10,22 @@ def build_ui(event_handler_function):
|
|
| 10 |
ui_components = {}
|
| 11 |
|
| 12 |
# Helper function to load thumbnails from the output folder.
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# All UI components, including tabs, must be created inside the same Gradio Blocks context.
|
| 24 |
with gr.Blocks() as demo:
|
|
|
|
| 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:
|