John6666 commited on
Commit
9329194
1 Parent(s): 86daee1

Upload 2 files

Browse files
Files changed (1) hide show
  1. dc.py +18 -8
dc.py CHANGED
@@ -323,6 +323,7 @@ class GuiSD:
323
  images, seed, image_list, metadata = model(**pipe_params)
324
  progress(1, desc="Inference completed.")
325
  if not isinstance(images, list): images = [images]
 
326
  img = []
327
  for image in images:
328
  img.append((image, None))
@@ -678,17 +679,11 @@ class GuiSD:
678
  }
679
 
680
  # Maybe fix lora issue: 'Cannot copy out of meta tensor; no data!''
681
- self.model.pipe.to("cuda:0" if torch.cuda.is_available() else "cpu")
682
 
683
  progress(1, desc="Inference preparation completed. Starting inference...")
684
 
685
- info_state = f"PROCESSING "
686
- info_state += ">"
687
- info_state = f"COMPLETED. Seeds: {str(seed)}"
688
- if vae_msg:
689
- info_state = info_state + "<br>" + vae_msg
690
- if msg_lora:
691
- info_state = info_state + "<br>" + "<br>".join(msg_lora)
692
  return self.infer_short(self.model, pipe_params, progress), info_state
693
  ## END MOD
694
 
@@ -1310,3 +1305,18 @@ def process_style_prompt(prompt: str, neg_prompt: str, styles_key: str = "None",
1310
  return gr.update(value=prompt), gr.update(value=neg_prompt)
1311
 
1312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  images, seed, image_list, metadata = model(**pipe_params)
324
  progress(1, desc="Inference completed.")
325
  if not isinstance(images, list): images = [images]
326
+ images = save_images(images, metadata)
327
  img = []
328
  for image in images:
329
  img.append((image, None))
 
679
  }
680
 
681
  # Maybe fix lora issue: 'Cannot copy out of meta tensor; no data!''
682
+ #self.model.pipe.to("cuda:0" if torch.cuda.is_available() else "cpu")
683
 
684
  progress(1, desc="Inference preparation completed. Starting inference...")
685
 
686
+ info_state = "" # for yield version
 
 
 
 
 
 
687
  return self.infer_short(self.model, pipe_params, progress), info_state
688
  ## END MOD
689
 
 
1305
  return gr.update(value=prompt), gr.update(value=neg_prompt)
1306
 
1307
 
1308
+ from PIL import Image
1309
+ def save_images(images: list[Image.Image], metadatas: list[str]):
1310
+ from PIL import PngImagePlugin
1311
+ try:
1312
+ output_images = []
1313
+ for image, metadata in zip(images, metadatas):
1314
+ info = PngImagePlugin.PngInfo()
1315
+ info.add_text("metadata", metadata)
1316
+ savefile = "image.png"
1317
+ image.save(savefile, "PNG", pnginfo=info)
1318
+ output_images.append(str(Path(savefile).resolve()))
1319
+ return output_images
1320
+ except Exception as e:
1321
+ print(f"Failed to save image file: {e}")
1322
+ raise Exception(f"Failed to save image file:") from e