Hermes Bot commited on
Commit
f8d77bc
·
1 Parent(s): a79dfdb

Restore PNG metadata writing in sd_image_pipeline after refactor

Browse files
Files changed (1) hide show
  1. core/pipelines/sd_image_pipeline.py +31 -2
core/pipelines/sd_image_pipeline.py CHANGED
@@ -239,9 +239,38 @@ class SdImagePipeline(BasePipeline):
239
  assembler=assembler,
240
  progress=progress
241
  )
242
-
243
- # The workflow already saved images and returned a deduplicated list of file paths.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  return results
 
245
  finally:
246
  for temp_file in temp_files_to_clean:
247
  if temp_file and os.path.exists(temp_file):
 
239
  assembler=assembler,
240
  progress=progress
241
  )
242
+ # -----------------------------------------------------------------
243
+ # Add generation metadata to the saved PNG files (if they exist).
244
+ # The original pipeline saved each image with a "parameters" field
245
+ # containing the prompt, seed, steps, sampler, etc. Some recent
246
+ # refactoring removed that block, causing the Gallery to have no
247
+ # metadata to display. We restore the behaviour here.
248
+ # -----------------------------------------------------------------
249
+ from PIL import Image, PngImagePlugin
250
+ import json, random, os
251
+ # Build the same param string used previously in `_gpu_logic`
252
+ params_string = f"{ui_inputs['positive_prompt']}\nNegative prompt: {ui_inputs['negative_prompt']}\n"
253
+ params_string += f"Steps: {ui_inputs['num_inference_steps']}, Sampler: {ui_inputs['sampler']}, Scheduler: {ui_inputs['scheduler']}, CFG scale: {ui_inputs['guidance_scale']}, Seed: {ui_inputs['seed']}, Size: {ui_inputs.get('width', 'N/A')}x{ui_inputs.get('height', 'N/A')}, Base Model: {model_display_name}"
254
+ if ui_inputs['task_type'] != 'txt2img':
255
+ params_string += f", Denoise: {ui_inputs.get('denoise', '')}"
256
+ if ui_inputs.get('clip_skip') and ui_inputs['clip_skip'] != 1:
257
+ params_string += f", Clip skip: {abs(ui_inputs['clip_skip'])}"
258
+ if loras_string:
259
+ params_string += f", {loras_string}"
260
+ # Attach metadata to each generated PNG (if it exists)
261
+ for path in results:
262
+ if not os.path.isfile(path):
263
+ continue
264
+ try:
265
+ with Image.open(path) as im:
266
+ meta = PngImagePlugin.PngInfo()
267
+ meta.add_text("parameters", params_string)
268
+ # Preserve existing info if any (e.g., EXIF)
269
+ im.save(path, "PNG", pnginfo=meta)
270
+ except Exception as e:
271
+ print(f"[WARN] Could not write generation metadata to {path}: {e}")
272
  return results
273
+
274
  finally:
275
  for temp_file in temp_files_to_clean:
276
  if temp_file and os.path.exists(temp_file):