diff --git a/.others/version.py b/.others/version.py index 50922f6..ac4beff 100644 --- a/.others/version.py +++ b/.others/version.py @@ -38,3 +38,23 @@ print(f"> File2 {file2}") with open(file2, "w") as f2: f2.writelines([f"version = \"{version}\"\n"]) + +# modify pyproject.toml file with @version +file3 = os.path.join(os.path.dirname(__file__), "../pyproject.toml") +print(f"> File3: {file3}") + +file3VersionFound = False +# lines = None +with open(file3, "r") as f: + lines = f.readlines() + for line in lines: + + if "version = " in line: + file3VersionFound = True + lines[lines.index(line)] = f"version = \"{version}\"\n" + +if not file3VersionFound: + raise RuntimeError(f"Version label not found in file: {file3}") + +with open(file3, "w") as f3: + f3.writelines(lines) diff --git a/__init__.py b/__init__.py index 55bde3b..ed1d33f 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ @author: Crystian @title: Crystools @nickname: Crystools -@version: 1.12.0 +@version: 1.13.0 @project: "https://github.com/crystian/ComfyUI-Crystools", @description: Plugins for multiples uses, mainly for debugging, you need them! IG: https://www.instagram.com/crystian.ia """ diff --git a/core/version.py b/core/version.py index 6f73501..e3d9739 100644 --- a/core/version.py +++ b/core/version.py @@ -1 +1 @@ -version = "1.12.0" +version = "1.13.0" diff --git a/docs/screwdriver.png b/docs/screwdriver.png new file mode 100644 index 0000000..61a0574 Binary files /dev/null and b/docs/screwdriver.png differ diff --git a/general/gpu.py b/general/gpu.py index 6250d3c..54ef2f1 100644 --- a/general/gpu.py +++ b/general/gpu.py @@ -39,9 +39,15 @@ class CGPUInfo: # deviceHandle = pynvml.nvmlDeviceGetHandleByIndex(0) for deviceIndex in range(self.cudaDevicesFound): deviceHandle = pynvml.nvmlDeviceGetHandleByIndex(deviceIndex) + gpuName = 'Unknown GPU' try: - gpuName = pynvml.nvmlDeviceGetName(deviceHandle).decode('utf-8', errors='ignore') + gpuName = pynvml.nvmlDeviceGetName(deviceHandle) + try: + gpuName = gpuName.decode('utf-8', errors='ignore') + except AttributeError as e: + pass + except UnicodeDecodeError as e: gpuName = 'Unknown GPU (decoding error)' print(f"UnicodeDecodeError: {e}") diff --git a/nodes/image.py b/nodes/image.py index 0df1799..f61a611 100644 --- a/nodes/image.py +++ b/nodes/image.py @@ -2,6 +2,7 @@ import os import random import sys import json +import piexif import hashlib from datetime import datetime import torch @@ -262,13 +263,15 @@ class CImageLoadWithMetadata: def execute(self, image): image_path = folder_paths.get_annotated_filepath(image) - img = Image.open(image_path) - if img.format == 'WEBP': + imgF = Image.open(image_path) + img, prompt, metadata = buildMetadata(image_path) + if imgF.format == 'WEBP': # Use piexif to extract EXIF data from WebP image - exif_data = piexif.load(image_path) - prompt, metadata = self.process_exif_data(exif_data) - else: - img, prompt, metadata = buildMetadata(image_path) + try: + exif_data = piexif.load(image_path) + prompt, metadata = self.process_exif_data(exif_data) + except ValueError: + prompt = {} img = ImageOps.exif_transpose(img) image = img.convert("RGB") @@ -281,7 +284,7 @@ class CImageLoadWithMetadata: mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu") return image, mask.unsqueeze(0), prompt, metadata - + def process_exif_data(self, exif_data): metadata = {} # 检查 '0th' 键下的 271 值,提取 Prompt 信息 @@ -306,9 +309,26 @@ class CImageLoadWithMetadata: except json.JSONDecodeError: # 如果转换失败,则将原始字符串存储在 metadata 中 metadata['workflow'] = workflow_data + metadata.update(exif_data) return metadata + @classmethod + def IS_CHANGED(cls, image): + image_path = folder_paths.get_annotated_filepath(image) + m = hashlib.sha256() + with open(image_path, 'rb') as f: + m.update(f.read()) + return m.digest().hex() + + @classmethod + def VALIDATE_INPUTS(cls, image): + if not folder_paths.exists_annotated_filepath(image): + return "Invalid image file: {}".format(image) + + return True + + class CImageSaveWithExtraMetadata(SaveImage): def __init__(self): super().__init__() @@ -371,7 +391,8 @@ class CImageSaveWithExtraMetadata(SaveImage): if metadata_extra is not None and metadata_extra != 'undefined': try: - metadata_extra = json.loads(f"{{{metadata_extra}}}") + # metadata_extra = json.loads(f"{{{metadata_extra}}}") // a fix? + metadata_extra = json.loads(metadata_extra) except Exception as e: logger.error(f"Error parsing metadata_extra (it will send as string), error: {e}") metadata_extra = {"extra": str(metadata_extra)} diff --git a/pyproject.toml b/pyproject.toml index a4a08d5..5e0f1da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,14 @@ -[project] -name = "comfyui-crystools" -description = "With this suit, you can see the resources monitor, progress bar & time elapsed, metadata and compare between two images, compare between two JSONs, show any value to console/display, pipes, and more!\nThis provides better nodes to load/save images, previews, etc, and see \"hidden\" data without loading a new workflow." -version = "1.0.0" -license = "LICENSE" -dependencies = ["deepdiff", "torch", "numpy", "Pillow>=9.5.0", "pynvml", "py-cpuinfo"] - -[project.urls] -Repository = "https://github.com/crystian/ComfyUI-Crystools" - -[tool.comfy] -PublisherId = "" -DisplayName = "ComfyUI-Crystools" -Icon = "" +[project] +name = "comfyui-crystools" +description = "With this suit, you can see the resources monitor, progress bar & time elapsed, metadata and compare between two images, compare between two JSONs, show any value to console/display, pipes, and more!\nThis provides better nodes to load/save images, previews, etc, and see \"hidden\" data without loading a new workflow." +version = "1.13.0" +license = "LICENSE" +dependencies = ["deepdiff", "torch", "numpy", "Pillow>=9.5.0", "pynvml", "py-cpuinfo"] + +[project.urls] +Repository = "https://github.com/crystian/ComfyUI-Crystools" + +[tool.comfy] +PublisherId = "crystian" +DisplayName = "ComfyUI-Crystools" +Icon = "https://raw.githubusercontent.com/crystian/ComfyUI-Crystools/main/docs/screwdriver.png" diff --git a/requirements.txt b/requirements.txt index 21f0496..d61acb5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ numpy Pillow>=9.5.0 pynvml py-cpuinfo +piexif diff --git a/version b/version index 0eed1a2..feaae22 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.12.0 +1.13.0