Skip to content

Commit 8071890

Browse files
authored
convert nodes_sdupscale.py to V3 schema (#9943)
1 parent 7ea173c commit 8071890

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

comfy_extras/nodes_sdupscale.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1+
from typing_extensions import override
2+
13
import torch
24
import comfy.utils
5+
from comfy_api.latest import ComfyExtension, io
36

4-
class SD_4XUpscale_Conditioning:
7+
class SD_4XUpscale_Conditioning(io.ComfyNode):
58
@classmethod
6-
def INPUT_TYPES(s):
7-
return {"required": { "images": ("IMAGE",),
8-
"positive": ("CONDITIONING",),
9-
"negative": ("CONDITIONING",),
10-
"scale_ratio": ("FLOAT", {"default": 4.0, "min": 0.0, "max": 10.0, "step": 0.01}),
11-
"noise_augmentation": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.001}),
12-
}}
13-
RETURN_TYPES = ("CONDITIONING", "CONDITIONING", "LATENT")
14-
RETURN_NAMES = ("positive", "negative", "latent")
15-
16-
FUNCTION = "encode"
9+
def define_schema(cls):
10+
return io.Schema(
11+
node_id="SD_4XUpscale_Conditioning",
12+
category="conditioning/upscale_diffusion",
13+
inputs=[
14+
io.Image.Input("images"),
15+
io.Conditioning.Input("positive"),
16+
io.Conditioning.Input("negative"),
17+
io.Float.Input("scale_ratio", default=4.0, min=0.0, max=10.0, step=0.01),
18+
io.Float.Input("noise_augmentation", default=0.0, min=0.0, max=1.0, step=0.001),
19+
],
20+
outputs=[
21+
io.Conditioning.Output(display_name="positive"),
22+
io.Conditioning.Output(display_name="negative"),
23+
io.Latent.Output(display_name="latent"),
24+
],
25+
)
1726

18-
CATEGORY = "conditioning/upscale_diffusion"
19-
20-
def encode(self, images, positive, negative, scale_ratio, noise_augmentation):
27+
@classmethod
28+
def execute(cls, images, positive, negative, scale_ratio, noise_augmentation):
2129
width = max(1, round(images.shape[-2] * scale_ratio))
2230
height = max(1, round(images.shape[-3] * scale_ratio))
2331

@@ -39,8 +47,16 @@ def encode(self, images, positive, negative, scale_ratio, noise_augmentation):
3947
out_cn.append(n)
4048

4149
latent = torch.zeros([images.shape[0], 4, height // 4, width // 4])
42-
return (out_cp, out_cn, {"samples":latent})
50+
return io.NodeOutput(out_cp, out_cn, {"samples":latent})
51+
52+
53+
class SdUpscaleExtension(ComfyExtension):
54+
@override
55+
async def get_node_list(self) -> list[type[io.ComfyNode]]:
56+
return [
57+
SD_4XUpscale_Conditioning,
58+
]
59+
4360

44-
NODE_CLASS_MAPPINGS = {
45-
"SD_4XUpscale_Conditioning": SD_4XUpscale_Conditioning,
46-
}
61+
async def comfy_entrypoint() -> SdUpscaleExtension:
62+
return SdUpscaleExtension()

0 commit comments

Comments
 (0)