Hermes Bot commited on
Commit
83b820a
·
1 Parent(s): d80d2b1

Remove auto metadata extraction; use drag-and-drop upload for info

Browse files
Files changed (1) hide show
  1. ui/events/run_handlers.py +3 -53
ui/events/run_handlers.py CHANGED
@@ -139,56 +139,6 @@ def create_run_event(prefix: str, task_type: str, ui_components: dict):
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, *_):
144
- # `selected` may be a string (filepath), a list, or a tuple containing the path.
145
- # Gradio can sometimes pass a tuple like (path, None) or a list of such tuples.
146
- # We extract the first string path we find.
147
- def extract_path(val):
148
- if isinstance(val, str):
149
- return val
150
- if isinstance(val, (list, tuple)):
151
- for item in val:
152
- result = extract_path(item)
153
- if result:
154
- return result
155
- return None
156
-
157
- path = extract_path(selected)
158
- if not path:
159
- print(f"[DEBUG] No valid image path extracted from {selected}")
160
- return "(ไม่มีข้อมูลเมตาดาต้า)"
161
-
162
- # Try to read metadata from the extracted path. If this fails (e.g., path points to a temporary Gradio copy), fall back to the most‑recent file in the output directory.
163
- meta = ""
164
- try:
165
- from PIL import Image
166
- with Image.open(path) as im:
167
- meta = im.info.get("parameters", "")
168
- print(f"[DEBUG] Metadata extracted from {path}: {meta}")
169
- except Exception as e:
170
- print(f"[DEBUG] Failed to read metadata from {path}: {e}")
171
- # Fallback: find latest file in the configured OUTPUT_DIR
172
- try:
173
- from pathlib import Path
174
- out_dir = Path(os.path.abspath(OUTPUT_DIR))
175
- files = sorted(out_dir.glob("*.png"), key=lambda p: p.stat().st_mtime, reverse=True)
176
- if files:
177
- fallback_path = files[0]
178
- with Image.open(fallback_path) as im2:
179
- meta = im2.info.get("parameters", "")
180
- print(f"[DEBUG] Fallback metadata from {fallback_path}: {meta}")
181
- except Exception as e2:
182
- print(f"[DEBUG] Fallback metadata extraction failed: {e2}")
183
-
184
- # If metadata exists, we can also include the filename for clarity
185
- if meta:
186
- filename = os.path.basename(path)
187
- return f"{filename}\n{meta}"
188
- else:
189
- return "(ไม่มีข้อมูลเมตาดาต้า)"
190
-
191
- # Connect the select event of the global gallery to update its metadata textbox
192
- gallery_tab = ui_components.get('gallery')
193
- if gallery_tab:
194
- gallery_tab.select(fn=_show_meta, inputs=gallery_tab, outputs=ui_components.get('gallery_metadata'))
 
139
  inputs=input_list_flat,
140
  outputs=[res_gal, ui_components.get('gallery')]
141
  )
142
+ # Auto metadata extraction on gallery selection removed.
143
+ # Users can now drag‑and‑drop an image onto the "Drag image here for info" component
144
+ # to view its generation info.