Upload modutils.py
Browse files- modutils.py +7 -4
modutils.py
CHANGED
@@ -329,18 +329,21 @@ def save_gallery_history(images, files, history_gallery, history_files, progress
|
|
329 |
return gr.update(value=output_gallery), gr.update(value=output_files, visible=True)
|
330 |
|
331 |
|
332 |
-
def save_image_history(image
|
333 |
-
|
334 |
basename = f"{model_name.split('/')[-1]}_{datetime.now(FILENAME_TIMEZONE).strftime('%Y%m%d_%H%M%S')}"
|
335 |
-
if image is None or (not isinstance(image, str) and not isinstance(image, Image.Image) and not isinstance(image, tuple)): return gr.update(), gr.update()
|
336 |
if not gallery: gallery = []
|
337 |
if not files: files = []
|
338 |
filename = f"{basename}.png"
|
339 |
if isinstance(image, tuple): image = image[0]
|
340 |
if isinstance(image, str): oldpath = Path(image)
|
341 |
-
|
342 |
oldpath = "temp.png"
|
343 |
image.save(oldpath)
|
|
|
|
|
|
|
344 |
newpath = oldpath
|
345 |
try:
|
346 |
if newpath != oldpath and oldpath.exists():
|
|
|
329 |
return gr.update(value=output_gallery), gr.update(value=output_files, visible=True)
|
330 |
|
331 |
|
332 |
+
def save_image_history(image, gallery, files, model_name: str, progress=gr.Progress(track_tqdm=True)):
|
333 |
+
import numpy as np
|
334 |
basename = f"{model_name.split('/')[-1]}_{datetime.now(FILENAME_TIMEZONE).strftime('%Y%m%d_%H%M%S')}"
|
335 |
+
if image is None or (not isinstance(image, str) and not isinstance(image, Image.Image) and not isinstance(image, np.array) and not isinstance(image, tuple)): return gr.update(), gr.update()
|
336 |
if not gallery: gallery = []
|
337 |
if not files: files = []
|
338 |
filename = f"{basename}.png"
|
339 |
if isinstance(image, tuple): image = image[0]
|
340 |
if isinstance(image, str): oldpath = Path(image)
|
341 |
+
elif isinstance(image, Image.Image):
|
342 |
oldpath = "temp.png"
|
343 |
image.save(oldpath)
|
344 |
+
elif isinstance(image, np.array):
|
345 |
+
oldpath = "temp.png"
|
346 |
+
Image.fromarray(image).convert('RGBA').save(oldpath)
|
347 |
newpath = oldpath
|
348 |
try:
|
349 |
if newpath != oldpath and oldpath.exists():
|