Initial commit

This commit is contained in:
ControlAltAI
2024-08-15 21:26:45 +05:30
commit c225a0119e
7 changed files with 150 additions and 0 deletions
+15
View File
@@ -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",
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+52
View File
@@ -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",
}
+70
View File
@@ -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"
}
+13
View File
@@ -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 = ""