37
37
import os
38
38
import math
39
39
import subprocess
40
-
40
+ import traceback
41
41
import pathlib
42
42
import os
43
- script_dir = os .path .dirname (os .path .realpath (__file__ ))
44
- extension_dir = pathlib .Path (script_dir ).parent
45
- sys .path .append (extension_dir )
43
+
44
+ # Not sure if this is needed
45
+ try :
46
+ script_dir = os .path .dirname (os .path .realpath (__file__ ))
47
+ extension_dir = pathlib .Path (script_dir ).parent
48
+ sys .path .append (extension_dir )
49
+ except :
50
+ sys .path .append ('extensions/stable-diffusion-webui-depthmap-script' )
46
51
47
52
48
53
from scripts .stereoimage_generation import create_stereoimages
91
96
depthmap_model_type = None
92
97
depthmap_deviceidx = None
93
98
99
+ commit_hash = None # TODO: understand why it would spam to stderr if changed to ... = get_commit_hash()
94
100
def get_commit_hash ():
95
- try :
96
- hash = subprocess .check_output ([os .environ .get ('GIT' , "git" ), "rev-parse" , "HEAD" ], shell = False , encoding = 'utf8' ).strip ()
97
- hash = hash [0 :8 ]
98
- return hash
99
- except Exception :
100
- return "<none>"
101
- commit_hash = get_commit_hash ()
101
+ global commit_hash
102
+ if commit_hash is None :
103
+ try :
104
+ commit_hash = subprocess .check_output (
105
+ [os .environ .get ('GIT' , "git" ), "rev-parse" , "HEAD" ],
106
+ cwd = pathlib .Path .cwd ().joinpath ('extensions/stable-diffusion-webui-depthmap-script/' ),
107
+ shell = False ,
108
+ stderr = subprocess .DEVNULL ,
109
+ encoding = 'utf8' ).strip ()[0 :8 ]
110
+ except Exception :
111
+ commit_hash = "<none>"
112
+ return commit_hash
113
+
102
114
103
115
def main_ui_panel (is_depth_tab ):
104
116
with gr .Blocks ():
@@ -335,8 +347,8 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
335
347
336
348
if len (inputimages ) == 0 or inputimages [0 ] == None :
337
349
return [], []
338
-
339
- print (f"\n { scriptname } { scriptversion } ({ commit_hash } )" )
350
+
351
+ print (f"\n { scriptname } { scriptversion } ({ get_commit_hash () } )" )
340
352
341
353
unload_sd_model ()
342
354
@@ -688,8 +700,10 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
688
700
if opts .samples_format == "png" :
689
701
try :
690
702
images .save_image (Image .fromarray (img_output ), outpath , "" , processed .all_seeds [count ], processed .all_prompts [count ], opts .samples_format , info = info , p = processed , suffix = "_depth" )
691
- except ValueError as ve :
692
- if not ('image has wrong mode' in str (ve ) or 'cannot write mode I;16 as JPEG' in str (ve )): raise ve
703
+ except Exception as ve :
704
+ if not ('image has wrong mode' in str (ve ) or 'I;16' in str (ve )): raise ve
705
+ print ('Catched exception: image has wrong mode!' )
706
+ traceback .print_exc ()
693
707
else :
694
708
images .save_image (Image .fromarray (img_output2 ), outpath , "" , processed .all_seeds [count ], processed .all_prompts [count ], opts .samples_format , info = info , p = processed , suffix = "_depth" )
695
709
elif save_depth :
@@ -698,8 +712,10 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
698
712
if opts .samples_format == "png" :
699
713
try :
700
714
images .save_image (Image .fromarray (img_output ), path = outpath , basename = basename , seed = None , prompt = None , extension = opts .samples_format , info = info , short_filename = True ,no_prompt = True , grid = False , pnginfo_section_name = "extras" , existing_info = None , forced_filename = None )
701
- except ValueError as ve :
702
- if not ('image has wrong mode' in str (ve ) or 'cannot write mode I;16 as JPEG' in str (ve )): raise ve
715
+ except Exception as ve :
716
+ if not ('image has wrong mode' in str (ve ) or 'I;16' in str (ve )): raise ve
717
+ print ('Catched exception: image has wrong mode!' )
718
+ traceback .print_exc ()
703
719
else :
704
720
images .save_image (Image .fromarray (img_output2 ), path = outpath , basename = basename , seed = None , prompt = None , extension = opts .samples_format , info = info , short_filename = True ,no_prompt = True , grid = False , pnginfo_section_name = "extras" , existing_info = None , forced_filename = None )
705
721
else :
0 commit comments