pr 1: fix finding the VAE

#3
by dummy9996 - opened
comfyui/ComfyUI-SeedVR2-1.4B-TinyVAE/__init__.py CHANGED
@@ -51,6 +51,7 @@ Environment
51
 
52
  import logging
53
  import os
 
54
 
55
  log = logging.getLogger(__name__)
56
 
@@ -81,24 +82,38 @@ COMFY_PRE_SCALES = True # ComfyUI already applied it before decode_ (veri
81
 
82
  _WEIGHT_NAME = "ema_vae_distill_fp16.safetensors"
83
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  def _find_weights():
86
  if os.environ.get("SEEDVR2_TINYVAE_PATH"):
87
  return os.environ["SEEDVR2_TINYVAE_PATH"]
88
  here = os.path.dirname(os.path.abspath(__file__))
 
89
  cands = [
90
  os.path.join(here, _WEIGHT_NAME),
91
- os.path.join(here, "..", _WEIGHT_NAME),
92
- os.path.join(here, "..", "..", _WEIGHT_NAME),
 
 
93
  ]
94
- try: # ComfyUI's own vae folder
95
- import folder_paths
96
- cands += [os.path.join(p, _WEIGHT_NAME) for p in folder_paths.get_folder_paths("vae")]
97
- except Exception:
98
- pass
99
  for c in cands:
100
  if os.path.exists(c):
 
101
  return os.path.abspath(c)
 
 
102
  return None
103
 
104
 
 
51
 
52
  import logging
53
  import os
54
+ import sys
55
 
56
  log = logging.getLogger(__name__)
57
 
 
82
 
83
  _WEIGHT_NAME = "ema_vae_distill_fp16.safetensors"
84
 
85
+ try:
86
+ import folder_paths
87
+ except ImportError:
88
+ comfy_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
89
+ sys.path.insert(0, comfy_path)
90
+ try:
91
+ import folder_paths
92
+ except ImportError:
93
+ folder_paths = None
94
+ log.warning("Could not import folder_paths, falling back to local path resolution")
95
 
96
  def _find_weights():
97
  if os.environ.get("SEEDVR2_TINYVAE_PATH"):
98
  return os.environ["SEEDVR2_TINYVAE_PATH"]
99
  here = os.path.dirname(os.path.abspath(__file__))
100
+
101
  cands = [
102
  os.path.join(here, _WEIGHT_NAME),
103
+ os.path.join(os.path.dirname(here), _WEIGHT_NAME),
104
+ os.path.join(folder_paths.get_folder_paths("vae")[0], _WEIGHT_NAME) if folder_paths and folder_paths.get_folder_paths("vae") else None,
105
+ *([os.path.join(p, _WEIGHT_NAME) for p in folder_paths.get_folder_paths("vae")] if folder_paths else []),
106
+ os.path.join(here, "models", _WEIGHT_NAME),
107
  ]
108
+
109
+ cands = [c for c in cands if c]
110
+
 
 
111
  for c in cands:
112
  if os.path.exists(c):
113
+ log.info(f"SeedVR2 TinyVAE: Found weights at {c}")
114
  return os.path.abspath(c)
115
+
116
+ log.warning(f"SeedVR2 TinyVAE: Could not find {_WEIGHT_NAME} in any of the searched locations: {cands}")
117
  return None
118
 
119