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