11# DepthMap can be run inside stable-duiffusion-webui, but also separately.
22# All the stable-duiffusion-webui stuff that the DepthMap relies on
33# must be resided in this file (or in the scripts folder).
4+ import pathlib
5+ from datetime import datetime
46
57try :
68 # stable-duiffusion-webui backbone
@@ -61,15 +63,21 @@ def get_hide_dirs():
6163 return modules .shared .hide_dirs
6264except :
6365 # Standalone backbone
64- print (" DepthMap did not detect stable-duiffusion-webui; launching with the standalone backbone.\n "
65- "The standalone backbone is not on par with the stable-duiffusion-webui backbone .\n "
66- "Some features may be missing or work differently. Please report bugs.\n " )
66+ print ( # " DepthMap did not detect stable-duiffusion-webui; launching with the standalone backbone.\n"
67+ " The standalone mode is not on par with the stable-duiffusion-webui mode .\n "
68+ " Some features may be missing or work differently. Please report bugs.\n " )
6769
6870 def save_image (image , path , basename , ** kwargs ):
6971 import os
7072 os .makedirs (path , exist_ok = True )
71- fullfn = os .path .join (path , f"{ get_next_sequence_number ()} -{ basename } .{ kwargs ['extension' ]} " )
72- image .save (fullfn , format = get_opt ('samples_format' , 'png' ))
73+ if 'suffix' not in kwargs or len (kwargs ['suffix' ]) == 0 :
74+ kwargs ['suffix' ] = ''
75+ else :
76+ kwargs ['suffix' ] = f"-{ kwargs ['suffix' ]} "
77+ format = get_opt ('samples_format' , kwargs ['extension' ])
78+ fullfn = os .path .join (
79+ path , f"{ basename } -{ get_next_sequence_number (path , basename )} { kwargs ['suffix' ]} .{ format } " )
80+ image .save (fullfn , format = format )
7381
7482 def torch_gc ():
7583 # TODO: is this really sufficient?
@@ -79,11 +87,13 @@ def torch_gc():
7987 torch .cuda .empty_cache ()
8088 torch .cuda .ipc_collect ()
8189
90+ launched_at = int (datetime .now ().timestamp ())
91+ backbone_current_seq_number = 0
92+
8293 def get_next_sequence_number (outpath = None , basename = None ):
83- # Don't really care what the number will be... As long as it is unique.
84- from datetime import datetime , timezone
85- import random
86- return int (f"{ int (datetime .now (timezone .utc ).timestamp ())} { random .randint (1000 ,9999 )} " )
94+ global backbone_current_seq_number
95+ backbone_current_seq_number += 1
96+ return int (f"{ launched_at } { backbone_current_seq_number :04} " )
8797
8898 def wrap_gradio_gpu_call (f ): return f # Displaying various stats is not supported
8999
@@ -99,7 +109,7 @@ def get_cmd_opt(name, default): return default # Configuring is not supported
99109
100110 def gather_ops (): return {} # Configuring is not supported
101111
102- def get_outpath (): return '.'
112+ def get_outpath (): return str ( pathlib . Path ( '.' , 'outputs' ))
103113
104114 def unload_sd_model (): pass # Not needed
105115
0 commit comments