Commit ·
e050d47
1
Parent(s): ceb007a
Fix syntax and deduplicate gallery loader
Browse files- 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 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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:
|