mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-12-17 18:13:01 +08:00
convert nodes_flux to V3 schema (#10122)
This commit is contained in:
parent
f1dd6e50f8
commit
90853fb9cd
@ -1,60 +1,80 @@
|
|||||||
import node_helpers
|
import node_helpers
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
|
from typing_extensions import override
|
||||||
|
from comfy_api.latest import ComfyExtension, io
|
||||||
|
|
||||||
class CLIPTextEncodeFlux:
|
|
||||||
|
class CLIPTextEncodeFlux(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def define_schema(cls):
|
||||||
return {"required": {
|
return io.Schema(
|
||||||
"clip": ("CLIP", ),
|
node_id="CLIPTextEncodeFlux",
|
||||||
"clip_l": ("STRING", {"multiline": True, "dynamicPrompts": True}),
|
category="advanced/conditioning/flux",
|
||||||
"t5xxl": ("STRING", {"multiline": True, "dynamicPrompts": True}),
|
inputs=[
|
||||||
"guidance": ("FLOAT", {"default": 3.5, "min": 0.0, "max": 100.0, "step": 0.1}),
|
io.Clip.Input("clip"),
|
||||||
}}
|
io.String.Input("clip_l", multiline=True, dynamic_prompts=True),
|
||||||
RETURN_TYPES = ("CONDITIONING",)
|
io.String.Input("t5xxl", multiline=True, dynamic_prompts=True),
|
||||||
FUNCTION = "encode"
|
io.Float.Input("guidance", default=3.5, min=0.0, max=100.0, step=0.1),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
io.Conditioning.Output(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
CATEGORY = "advanced/conditioning/flux"
|
@classmethod
|
||||||
|
def execute(cls, clip, clip_l, t5xxl, guidance) -> io.NodeOutput:
|
||||||
def encode(self, clip, clip_l, t5xxl, guidance):
|
|
||||||
tokens = clip.tokenize(clip_l)
|
tokens = clip.tokenize(clip_l)
|
||||||
tokens["t5xxl"] = clip.tokenize(t5xxl)["t5xxl"]
|
tokens["t5xxl"] = clip.tokenize(t5xxl)["t5xxl"]
|
||||||
|
|
||||||
return (clip.encode_from_tokens_scheduled(tokens, add_dict={"guidance": guidance}), )
|
return io.NodeOutput(clip.encode_from_tokens_scheduled(tokens, add_dict={"guidance": guidance}))
|
||||||
|
|
||||||
class FluxGuidance:
|
encode = execute # TODO: remove
|
||||||
|
|
||||||
|
|
||||||
|
class FluxGuidance(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def define_schema(cls):
|
||||||
return {"required": {
|
return io.Schema(
|
||||||
"conditioning": ("CONDITIONING", ),
|
node_id="FluxGuidance",
|
||||||
"guidance": ("FLOAT", {"default": 3.5, "min": 0.0, "max": 100.0, "step": 0.1}),
|
category="advanced/conditioning/flux",
|
||||||
}}
|
inputs=[
|
||||||
|
io.Conditioning.Input("conditioning"),
|
||||||
|
io.Float.Input("guidance", default=3.5, min=0.0, max=100.0, step=0.1),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
io.Conditioning.Output(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = ("CONDITIONING",)
|
@classmethod
|
||||||
FUNCTION = "append"
|
def execute(cls, conditioning, guidance) -> io.NodeOutput:
|
||||||
|
|
||||||
CATEGORY = "advanced/conditioning/flux"
|
|
||||||
|
|
||||||
def append(self, conditioning, guidance):
|
|
||||||
c = node_helpers.conditioning_set_values(conditioning, {"guidance": guidance})
|
c = node_helpers.conditioning_set_values(conditioning, {"guidance": guidance})
|
||||||
return (c, )
|
return io.NodeOutput(c)
|
||||||
|
|
||||||
|
append = execute # TODO: remove
|
||||||
|
|
||||||
|
|
||||||
class FluxDisableGuidance:
|
class FluxDisableGuidance(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def define_schema(cls):
|
||||||
return {"required": {
|
return io.Schema(
|
||||||
"conditioning": ("CONDITIONING", ),
|
node_id="FluxDisableGuidance",
|
||||||
}}
|
category="advanced/conditioning/flux",
|
||||||
|
description="This node completely disables the guidance embed on Flux and Flux like models",
|
||||||
|
inputs=[
|
||||||
|
io.Conditioning.Input("conditioning"),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
io.Conditioning.Output(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = ("CONDITIONING",)
|
@classmethod
|
||||||
FUNCTION = "append"
|
def execute(cls, conditioning) -> io.NodeOutput:
|
||||||
|
|
||||||
CATEGORY = "advanced/conditioning/flux"
|
|
||||||
DESCRIPTION = "This node completely disables the guidance embed on Flux and Flux like models"
|
|
||||||
|
|
||||||
def append(self, conditioning):
|
|
||||||
c = node_helpers.conditioning_set_values(conditioning, {"guidance": None})
|
c = node_helpers.conditioning_set_values(conditioning, {"guidance": None})
|
||||||
return (c, )
|
return io.NodeOutput(c)
|
||||||
|
|
||||||
|
append = execute # TODO: remove
|
||||||
|
|
||||||
|
|
||||||
PREFERED_KONTEXT_RESOLUTIONS = [
|
PREFERED_KONTEXT_RESOLUTIONS = [
|
||||||
@ -78,52 +98,73 @@ PREFERED_KONTEXT_RESOLUTIONS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class FluxKontextImageScale:
|
class FluxKontextImageScale(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def define_schema(cls):
|
||||||
return {"required": {"image": ("IMAGE", ),
|
return io.Schema(
|
||||||
},
|
node_id="FluxKontextImageScale",
|
||||||
}
|
category="advanced/conditioning/flux",
|
||||||
|
description="This node resizes the image to one that is more optimal for flux kontext.",
|
||||||
|
inputs=[
|
||||||
|
io.Image.Input("image"),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
io.Image.Output(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = ("IMAGE",)
|
@classmethod
|
||||||
FUNCTION = "scale"
|
def execute(cls, image) -> io.NodeOutput:
|
||||||
|
|
||||||
CATEGORY = "advanced/conditioning/flux"
|
|
||||||
DESCRIPTION = "This node resizes the image to one that is more optimal for flux kontext."
|
|
||||||
|
|
||||||
def scale(self, image):
|
|
||||||
width = image.shape[2]
|
width = image.shape[2]
|
||||||
height = image.shape[1]
|
height = image.shape[1]
|
||||||
aspect_ratio = width / height
|
aspect_ratio = width / height
|
||||||
_, width, height = min((abs(aspect_ratio - w / h), w, h) for w, h in PREFERED_KONTEXT_RESOLUTIONS)
|
_, width, height = min((abs(aspect_ratio - w / h), w, h) for w, h in PREFERED_KONTEXT_RESOLUTIONS)
|
||||||
image = comfy.utils.common_upscale(image.movedim(-1, 1), width, height, "lanczos", "center").movedim(1, -1)
|
image = comfy.utils.common_upscale(image.movedim(-1, 1), width, height, "lanczos", "center").movedim(1, -1)
|
||||||
return (image, )
|
return io.NodeOutput(image)
|
||||||
|
|
||||||
|
scale = execute # TODO: remove
|
||||||
|
|
||||||
|
|
||||||
class FluxKontextMultiReferenceLatentMethod:
|
class FluxKontextMultiReferenceLatentMethod(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def define_schema(cls):
|
||||||
return {"required": {
|
return io.Schema(
|
||||||
"conditioning": ("CONDITIONING", ),
|
node_id="FluxKontextMultiReferenceLatentMethod",
|
||||||
"reference_latents_method": (("offset", "index", "uxo/uno"), ),
|
category="advanced/conditioning/flux",
|
||||||
}}
|
inputs=[
|
||||||
|
io.Conditioning.Input("conditioning"),
|
||||||
|
io.Combo.Input(
|
||||||
|
"reference_latents_method",
|
||||||
|
options=["offset", "index", "uxo/uno"],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
io.Conditioning.Output(),
|
||||||
|
],
|
||||||
|
is_experimental=True,
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = ("CONDITIONING",)
|
@classmethod
|
||||||
FUNCTION = "append"
|
def execute(cls, conditioning, reference_latents_method) -> io.NodeOutput:
|
||||||
EXPERIMENTAL = True
|
|
||||||
|
|
||||||
CATEGORY = "advanced/conditioning/flux"
|
|
||||||
|
|
||||||
def append(self, conditioning, reference_latents_method):
|
|
||||||
if "uxo" in reference_latents_method or "uso" in reference_latents_method:
|
if "uxo" in reference_latents_method or "uso" in reference_latents_method:
|
||||||
reference_latents_method = "uxo"
|
reference_latents_method = "uxo"
|
||||||
c = node_helpers.conditioning_set_values(conditioning, {"reference_latents_method": reference_latents_method})
|
c = node_helpers.conditioning_set_values(conditioning, {"reference_latents_method": reference_latents_method})
|
||||||
return (c, )
|
return io.NodeOutput(c)
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
append = execute # TODO: remove
|
||||||
"CLIPTextEncodeFlux": CLIPTextEncodeFlux,
|
|
||||||
"FluxGuidance": FluxGuidance,
|
|
||||||
"FluxDisableGuidance": FluxDisableGuidance,
|
class FluxExtension(ComfyExtension):
|
||||||
"FluxKontextImageScale": FluxKontextImageScale,
|
@override
|
||||||
"FluxKontextMultiReferenceLatentMethod": FluxKontextMultiReferenceLatentMethod,
|
async def get_node_list(self) -> list[type[io.ComfyNode]]:
|
||||||
}
|
return [
|
||||||
|
CLIPTextEncodeFlux,
|
||||||
|
FluxGuidance,
|
||||||
|
FluxDisableGuidance,
|
||||||
|
FluxKontextImageScale,
|
||||||
|
FluxKontextMultiReferenceLatentMethod,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def comfy_entrypoint() -> FluxExtension:
|
||||||
|
return FluxExtension()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user