mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-30 10:57:23 +08:00
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Waiting to run
Execution Tests / test (macos-latest) (push) Waiting to run
Execution Tests / test (ubuntu-latest) (push) Waiting to run
Execution Tests / test (windows-latest) (push) Waiting to run
Test server launches without errors / test (push) Waiting to run
Unit Tests / test (macos-latest) (push) Waiting to run
Unit Tests / test (ubuntu-latest) (push) Waiting to run
Unit Tests / test (windows-2022) (push) Waiting to run
* Move dataset/text nodes to text category * Rename category utils into utilities * Rename category api node into partner * Move categories conditioning, latent, sampling, model_patches, training, etc. under model category * Dispatch partner nodes in to 3d, audio, image, text, video categories * Move PreviewAny node to utilities category
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
from typing_extensions import override
|
|
|
|
import torch
|
|
import comfy.utils
|
|
from comfy_api.latest import ComfyExtension, io
|
|
|
|
class SD_4XUpscale_Conditioning(io.ComfyNode):
|
|
@classmethod
|
|
def define_schema(cls):
|
|
return io.Schema(
|
|
node_id="SD_4XUpscale_Conditioning",
|
|
category="model/conditioning/upscale_diffusion",
|
|
inputs=[
|
|
io.Image.Input("images"),
|
|
io.Conditioning.Input("positive"),
|
|
io.Conditioning.Input("negative"),
|
|
io.Float.Input("scale_ratio", default=4.0, min=0.0, max=10.0, step=0.01),
|
|
io.Float.Input("noise_augmentation", default=0.0, min=0.0, max=1.0, step=0.001, advanced=True),
|
|
],
|
|
outputs=[
|
|
io.Conditioning.Output(display_name="positive"),
|
|
io.Conditioning.Output(display_name="negative"),
|
|
io.Latent.Output(display_name="latent"),
|
|
],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, images, positive, negative, scale_ratio, noise_augmentation):
|
|
width = max(1, round(images.shape[-2] * scale_ratio))
|
|
height = max(1, round(images.shape[-3] * scale_ratio))
|
|
|
|
pixels = comfy.utils.common_upscale((images.movedim(-1,1) * 2.0) - 1.0, width // 4, height // 4, "bilinear", "center")
|
|
|
|
out_cp = []
|
|
out_cn = []
|
|
|
|
for t in positive:
|
|
n = [t[0], t[1].copy()]
|
|
n[1]['concat_image'] = pixels
|
|
n[1]['noise_augmentation'] = noise_augmentation
|
|
out_cp.append(n)
|
|
|
|
for t in negative:
|
|
n = [t[0], t[1].copy()]
|
|
n[1]['concat_image'] = pixels
|
|
n[1]['noise_augmentation'] = noise_augmentation
|
|
out_cn.append(n)
|
|
|
|
latent = torch.zeros([images.shape[0], 4, height // 4, width // 4])
|
|
return io.NodeOutput(out_cp, out_cn, {"samples":latent})
|
|
|
|
|
|
class SdUpscaleExtension(ComfyExtension):
|
|
@override
|
|
async def get_node_list(self) -> list[type[io.ComfyNode]]:
|
|
return [
|
|
SD_4XUpscale_Conditioning,
|
|
]
|
|
|
|
|
|
async def comfy_entrypoint() -> SdUpscaleExtension:
|
|
return SdUpscaleExtension()
|