Upload modutils.py
Browse files- modutils.py +4 -4
modutils.py
CHANGED
@@ -337,7 +337,6 @@ def save_image_history(image, gallery, files, model_name: str, progress=gr.Progr
|
|
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):
|
@@ -346,14 +345,15 @@ def save_image_history(image, gallery, files, model_name: str, progress=gr.Progr
|
|
346 |
elif isinstance(image, np.ndarray):
|
347 |
oldpath = "temp.png"
|
348 |
Image.fromarray(image).convert('RGBA').save(oldpath)
|
349 |
-
|
|
|
350 |
shutil.copy(oldpath.resolve(), Path(filename).resolve())
|
351 |
newpath = Path(filename).resolve()
|
|
|
|
|
352 |
except Exception as e:
|
353 |
print(e)
|
354 |
finally:
|
355 |
-
files.insert(0, str(newpath))
|
356 |
-
gallery.insert(0, (str(newpath), str(filename)))
|
357 |
return gr.update(value=gallery), gr.update(value=files, visible=True)
|
358 |
|
359 |
|
|
|
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 |
if isinstance(image, tuple): image = image[0]
|
341 |
if isinstance(image, str): oldpath = Path(image)
|
342 |
elif isinstance(image, Image.Image):
|
|
|
345 |
elif isinstance(image, np.ndarray):
|
346 |
oldpath = "temp.png"
|
347 |
Image.fromarray(image).convert('RGBA').save(oldpath)
|
348 |
+
newpath = oldpath
|
349 |
+
if oldpath.exists():
|
350 |
shutil.copy(oldpath.resolve(), Path(filename).resolve())
|
351 |
newpath = Path(filename).resolve()
|
352 |
+
files.insert(0, str(newpath))
|
353 |
+
gallery.insert(0, (str(newpath), str(filename)))
|
354 |
except Exception as e:
|
355 |
print(e)
|
356 |
finally:
|
|
|
|
|
357 |
return gr.update(value=gallery), gr.update(value=files, visible=True)
|
358 |
|
359 |
|