Hermes Bot commited on
Commit
d80d2b1
·
1 Parent(s): 8a603b7

Refresh global gallery after generation

Browse files
Files changed (1) hide show
  1. ui/events/run_handlers.py +29 -5
ui/events/run_handlers.py CHANGED
@@ -94,11 +94,33 @@ def create_run_event(prefix: str, task_type: str, ui_components: dict):
94
 
95
  return ui_dict
96
 
97
- # Helper to run generation and return only the image paths (metadata handled separately in Gallery)
98
- def _run_with_meta(*args, progress=gr.Progress(track_tqdm=True)):
 
 
 
99
  ui_dict = create_ui_inputs_dict(*args)
100
  results = generate_image_wrapper(ui_dict, progress)
101
- return results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  run_btn = ui_components.get(f'run_{prefix}') or ui_components.get(f'{prefix}_run_button')
104
  res_gal = ui_components.get(f'result_{prefix}') or ui_components.get(f'{prefix}_output_gallery')
@@ -110,10 +132,12 @@ def create_run_event(prefix: str, task_type: str, ui_components: dict):
110
  # The Gallery component loads images via demo.load() on startup.
111
  # No need to add it to the run button outputs.
112
 
 
 
113
  run_btn.click(
114
- fn=_run_with_meta,
115
  inputs=input_list_flat,
116
- outputs=[res_gal]
117
  )
118
  # When a user selects an image from the global Gallery tab, load its generation info
119
  def _show_meta(selected, *_):
 
94
 
95
  return ui_dict
96
 
97
+ # Helper to run generation and refresh the global Gallery.
98
+ def _run_and_refresh(*args, progress=gr.Progress(track_tqdm=True)):
99
+ """Run the generation pipeline, then return both the tab-specific results
100
+ and the updated list of images for the Global Gallery.
101
+ """
102
  ui_dict = create_ui_inputs_dict(*args)
103
  results = generate_image_wrapper(ui_dict, progress)
104
+ # Re-scan the output folder for all image files (same logic as layout.load_gallery_images)
105
+ try:
106
+ from core.settings import OUTPUT_DIR
107
+ import os
108
+ out_dir = os.path.abspath(OUTPUT_DIR)
109
+ seen = set()
110
+ gallery_paths = []
111
+ if os.path.isdir(out_dir):
112
+ for fname in sorted(os.listdir(out_dir)):
113
+ low = fname.lower()
114
+ if low.endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
115
+ base = os.path.splitext(fname)[0]
116
+ if base not in seen:
117
+ seen.add(base)
118
+ gallery_paths.append(os.path.join(out_dir, fname))
119
+ except Exception as e:
120
+ print(f"[DEBUG] Failed to refresh global gallery: {e}")
121
+ gallery_paths = []
122
+ # Return a tuple: (tab result images, global gallery list)
123
+ return results, gallery_paths
124
 
125
  run_btn = ui_components.get(f'run_{prefix}') or ui_components.get(f'{prefix}_run_button')
126
  res_gal = ui_components.get(f'result_{prefix}') or ui_components.get(f'{prefix}_output_gallery')
 
132
  # The Gallery component loads images via demo.load() on startup.
133
  # No need to add it to the run button outputs.
134
 
135
+ # When the Run button is pressed, update both the tab-specific result gallery
136
+ # and the global Gallery tab.
137
  run_btn.click(
138
+ fn=_run_and_refresh,
139
  inputs=input_list_flat,
140
+ outputs=[res_gal, ui_components.get('gallery')]
141
  )
142
  # When a user selects an image from the global Gallery tab, load its generation info
143
  def _show_meta(selected, *_):