Files
JaredTherriault-ComfyUI-JNodes/py/utils.py
T
JaredTherriault 7ceb555e56 Initial Commit
-ImageDrawer (image feed, lora picker, image history, etc)
-EditAttention improvements
-Status indicators (percentage in title, favicon, progress bar on floating menu)
-Font control for textareas
-Token count node
-png_info manipulation nodes
-Synced string literals with external text files
-Parameter lists
-Save Video improvements over VHS
-Custom modal to replace lightbox
-Mouse over images to see exif/png_info
-Yet another dynamic prompts implementation with randomization controls
-Yet another Wildcards implementation
-Commenting out prompts support (just add # before each line you want to be ignored or encapsulate specific text on a line with ## on either side "## Commented text ##") built into Wildcards node, will be separated next time
-Prompt Editor (search and replace text in any text, intended for prompts to change certain trigger words, for example an embedding named '3mb3dd1n4' can be changed to 'embedding')
-Selector nodes that can be randomized based on seed (e.g. to select a random checkpoint name)
-Get Temp Directory, Get Output Directory
2024-01-15 13:36:49 -08:00

61 lines
1.7 KiB
Python

import os
import re
import folder_paths
from .logger import logger
import torch
import random
import numpy as np
from PIL import Image
from typing import Dict, List, Optional, Union
class AnyType(str):
"""A special class that is always equal in not equal comparisons. Credit to pythongosssss and rgthree"""
def __ne__(self, __value: object) -> bool:
return False
any = AnyType("*")
VIDEO_FORMATS_DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "video_formats")
VIDEO_FORMATS = [x[:-5] for x in os.listdir(VIDEO_FORMATS_DIRECTORY)]
JNODES_IMAGE_FORMAT_TYPES = ["jpg", "png", "gif", "webp", "apng", "mjpeg"] + VIDEO_FORMATS
JNODES_VAE_LIST = ["Baked VAE"] + folder_paths.get_filename_list("vae")
ACCEPTED_VIDEO_EXTENSIONS = ['webm', 'mp4', 'mkv']
ACCEPTED_IMAGE_EXTENSIONS = ['gif', 'webp', 'apng', 'mjpeg']
@staticmethod
def return_random_int(min = 1, max = 100000):
return random.randint(min, max)
def make_exclusive_list(original_list, items_to_remove):
return [item for item in original_list if item not in items_to_remove]
def get_extension(filename):
file_parts = filename.split('.')
return len(file_parts) > 1 and file_parts[-1]
def is_webp(filename):
return get_extension(filename) == "webp"
def is_gif(filename):
return get_extension(filename) == "gif"
def is_video(filename):
return get_extension(filename) in ACCEPTED_VIDEO_EXTENSIONS
def pil2tensor(image: Union[Image.Image, List[Image.Image]]) -> torch.Tensor:
if isinstance(image, list):
return torch.cat([pil2tensor(img) for img in image], dim=0)
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)