fred-dev/comfy_ui_ali
0
1import hashlib2import torch3 4from comfy.cli_args import args5 6from PIL import ImageFile, UnidentifiedImageError7 8def conditioning_set_values(conditioning, values={}):9 c = []10 for t in conditioning:11 n = [t[0], t[1].copy()]12 for k in values:13 n[1][k] = values[k]14 c.append(n)15 16 return c17 18def pillow(fn, arg):19 prev_value = None20 try:21 x = fn(arg)22 except (OSError, UnidentifiedImageError, ValueError): #PIL issues #4472 and #2445, also fixes ComfyUI issue #341623 prev_value = ImageFile.LOAD_TRUNCATED_IMAGES24 ImageFile.LOAD_TRUNCATED_IMAGES = True25 x = fn(arg)26 finally:27 if prev_value is not None:28 ImageFile.LOAD_TRUNCATED_IMAGES = prev_value29 return x30 31def hasher():32 hashfuncs = {33 "md5": hashlib.md5,34 "sha1": hashlib.sha1,35 "sha256": hashlib.sha256,36 "sha512": hashlib.sha51237 }38 return hashfuncs[args.default_hashing_function]39 40def string_to_torch_dtype(string):41 if string == "fp32":42 return torch.float3243 if string == "fp16":44 return torch.float1645 if string == "bf16":46 return torch.bfloat1647 