assistanttttttt commited on
Commit
07b236d
·
1 Parent(s): 0ea9e4a

Deduplicate gallery images by base name to avoid duplicate extensions

Browse files
Files changed (1) hide show
  1. 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
- # 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:
 
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: