Commit ·
07b236d
1
Parent(s): 0ea9e4a
Deduplicate gallery images by base name to avoid duplicate extensions
Browse files- ui/layout.py +15 -6
ui/layout.py
CHANGED
|
@@ -15,16 +15,25 @@ def build_ui(event_handler_function):
|
|
| 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 |
-
|
| 22 |
-
|
| 23 |
for fname in sorted(os.listdir(output_dir)):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# All UI components, including tabs, must be created inside the same Gradio Blocks context.
|
| 30 |
with gr.Blocks() as demo:
|
|
|
|
| 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 |
+
"""Return a deduplicated list of image paths.
|
| 19 |
+
If multiple files share the same stem (e.g., ``img.png`` and ``img.webp``),
|
| 20 |
+
only the first encountered file (based on sorted order) is kept. This prevents
|
| 21 |
+
the Gallery tab from displaying duplicate visual entries that arise from
|
| 22 |
+
different extensions of the same generated image.
|
| 23 |
+
"""
|
| 24 |
output_dir = os.path.abspath(OUTPUT_DIR)
|
| 25 |
if not os.path.isdir(output_dir):
|
| 26 |
return []
|
| 27 |
+
seen_bases = set()
|
| 28 |
+
image_paths = []
|
| 29 |
for fname in sorted(os.listdir(output_dir)):
|
| 30 |
+
low = fname.lower()
|
| 31 |
+
if low.endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
|
| 32 |
+
base = os.path.splitext(fname)[0]
|
| 33 |
+
if base not in seen_bases:
|
| 34 |
+
seen_bases.add(base)
|
| 35 |
+
image_paths.append(os.path.join(output_dir, fname))
|
| 36 |
+
return image_paths
|
| 37 |
|
| 38 |
# All UI components, including tabs, must be created inside the same Gradio Blocks context.
|
| 39 |
with gr.Blocks() as demo:
|