commit c225a0119e52f8c644b139890caadbb5e19e2a6d Author: ControlAltAI Date: Thu Aug 15 21:26:45 2024 +0530 Initial commit diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e7a3980 --- /dev/null +++ b/__init__.py @@ -0,0 +1,15 @@ +from .flux_resolution_cal_node import FluxResolutionNode +from .flux_sampler_node import FluxSampler + +print("Initializing Flux Resolution Node and Flux Sampler Node...") + +# Registering the nodes +NODE_CLASS_MAPPINGS = { + "FluxResolutionNode": FluxResolutionNode, + "FluxSampler": FluxSampler, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "FluxResolutionNode": "Flux Resolution Calculator", + "FluxSampler": "Flux Sampler", +} \ No newline at end of file diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..ccfce0e Binary files /dev/null and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/__pycache__/flux_resolution_cal_node.cpython-312.pyc b/__pycache__/flux_resolution_cal_node.cpython-312.pyc new file mode 100644 index 0000000..29a893f Binary files /dev/null and b/__pycache__/flux_resolution_cal_node.cpython-312.pyc differ diff --git a/__pycache__/flux_sampler_node.cpython-312.pyc b/__pycache__/flux_sampler_node.cpython-312.pyc new file mode 100644 index 0000000..f90586b Binary files /dev/null and b/__pycache__/flux_sampler_node.cpython-312.pyc differ diff --git a/flux_resolution_cal_node.py b/flux_resolution_cal_node.py new file mode 100644 index 0000000..b67066f --- /dev/null +++ b/flux_resolution_cal_node.py @@ -0,0 +1,52 @@ +class FluxResolutionNode: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "megapixel": (["0.1", "0.5", "1.0", "1.5", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5"], {"default": "1.0"}), + "aspect_ratio": ([ + "1:1 (Square)", + "2:3 (Portrait)", "4:5 (Portrait)", "5:8 (Portrait)", + "9:16 (Portrait)", "9:19 (Tall)", "9:21 (Tall)", "9:32 (Tall)", + "3:2 (Landscape)", "5:4 (Landscape)", "8:5 (Landscape)", + "16:9 (Landscape)", "19:9 (Ultrawide)", "21:9 (Ultrawide)", "32:9 (Ultrawide)" + ], {"default": "1:1 (Square)"}), + } + } + + RETURN_TYPES = ("INT", "INT", "STRING") + RETURN_NAMES = ("width", "height", "resolution") + FUNCTION = "calculate_dimensions" + CATEGORY = "ControlAltAI Nodes/Flux" + OUTPUT_NODE = True + + def calculate_dimensions(self, megapixel, aspect_ratio): + megapixel = float(megapixel) + # Extract the numeric ratio + numeric_ratio = aspect_ratio.split(' ')[0] + width_ratio, height_ratio = map(int, numeric_ratio.split(':')) + total_pixels = megapixel * 1_000_000 + dimension = (total_pixels / (width_ratio * height_ratio)) ** 0.5 + width = int(dimension * width_ratio) + height = int(dimension * height_ratio) + + # Determine rounding factor based on megapixel value + if megapixel in [0.1, 0.5, 1.0, 1.5]: + round_to = 8 + if megapixel in [1.0, 1.5]: + round_to = 64 + else: # 2.0 and above + round_to = 32 + width = round(width / round_to) * round_to + height = round(height / round_to) * round_to + + resolution = f"{width} x {height}" + return width, height, resolution + +NODE_CLASS_MAPPINGS = { + "FluxResolutionNode": FluxResolutionNode, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "FluxResolutionNode": "Flux Resolution Calculator", +} diff --git a/flux_sampler_node.py b/flux_sampler_node.py new file mode 100644 index 0000000..5e9c40b --- /dev/null +++ b/flux_sampler_node.py @@ -0,0 +1,70 @@ +import comfy.samplers +import torch +import comfy.sample +import latent_preview + +FLUX_SAMPLER_NAMES = [ + "euler", "heun", "heunpp2", "dpm_2", "dpm_2_ancestral", "lms", "dpmpp_2m", + "ipndm", "ipndm_v", "deis", "ddim", "uni_pc", "uni_pc_bh2" +] + +FLUX_SCHEDULER_NAMES = ["simple", "normal", "sgm_uniform", "ddim_uniform", "beta"] + +class FluxSampler: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "model": ("MODEL",), + "conditioning": ("CONDITIONING",), + "latent_image": ("LATENT",), + "sampler_name": (FLUX_SAMPLER_NAMES,), + "scheduler": (FLUX_SCHEDULER_NAMES,), + "steps": ("INT", {"default": 20, "min": 1, "max": 10000}), + "denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}), + "noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), + } + } + + RETURN_TYPES = ("LATENT",) + RETURN_NAMES = ("latent",) + FUNCTION = "sample" + CATEGORY = "ControlAltAI Nodes/Flux" + + def sample(self, model, conditioning, latent_image, sampler_name, scheduler, steps, denoise, noise_seed): + device = comfy.model_management.get_torch_device() + + # Create sampler + sampler = comfy.samplers.KSampler(model, steps=steps, device=device, sampler=sampler_name, scheduler=scheduler, denoise=denoise) + + # Prepare latent + latent = latent_image.copy() + latent_image = latent["samples"] + + # Prepare noise + noise = comfy.sample.prepare_noise(latent_image, noise_seed) + + # Prepare conditioning + positive = conditioning + negative = [] # Empty list for negative conditioning + + # Sampling + callback = latent_preview.prepare_callback(model, steps) + disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED + + samples = sampler.sample(noise, positive, negative, cfg=1.0, latent_image=latent_image, + force_full_denoise=True, denoise_mask=None, callback=callback, + disable_pbar=disable_pbar, seed=noise_seed) + + out = latent.copy() + out["samples"] = samples + + return (out,) + +NODE_CLASS_MAPPINGS = { + "FluxSampler": FluxSampler +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "FluxSampler": "Flux Sampler" +} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e89b37d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[project] +name = "ControlAltAI Nodes" +description = "Quality fo Life Nodes from ControlAltAI. FLux Resolution Calculator and Sampler." +version = "1.0.0" +license = { file = "LICENSE" } + +[project.urls] +Repository = "https://github.com/pythongosssss/ComfyUI-Custom-Scripts" + +[tool.comfy] +PublisherId = "ControlAltAI" +DisplayName = "ControlAltAI Nodes" +Icon = ""