"""Radiance MiniMax: drive a Radiance MiniMax-H3 server (/v1/videos) from ComfyUI. The node is a pure HTTP client: the ~50-60 GiB model (container-dependent) runs in the radiance server process (this box or any TP2 box on the LAN), so it costs ComfyUI no VRAM. Prompt: `prompt` is a widget AND an input socket -- wire your LLM prompt enhancer's STRING output straight into it and the wire wins over what is typed. Media is purely wire-driven: image_1..9, video_1..3, video_audio_1..3 (a video's soundtrack, its own socket) and audio_1..3 (standalone reference audio). Which ones are live depends on the task: t2va -- none i2va -- image_1 -> first frame l2va -- image_1 -> last frame fl2va -- image_1 -> first frame, image_2 -> last frame ref2va -- all: image_1..9 + video_1..3 + video_audio_1..3 + audio_1..3 Connections a task does not use are ignored (with a console warning), and for ref2va the slots must be filled in order -- ref image 3 without 2 would shift the server's conditioning groups. Everything is documented again in the node's ? help pane (the description below), which ComfyUI renders as markdown. """ import io as _io import json import logging import os import re import tempfile import time import wave import requests import folder_paths from comfy_api.latest import io, ui, Types from comfy_api.input_impl import VideoFromFile POLL_SECONDS = 3.0 KEEPALIVE_SECONDS = 30.0 LOG = "RadianceMiniMax" # The size law the minimaxh3 plugin declares (arch/minimaxh3/minimaxh3.cpp): # sides are multiples of 32 px from 256, at most 4:1, at most 1344x768 of area # -- and that law now holds for EVERY task. Keyframes are resized to the exact # output canvas and VAE-encoded as one frame; the plugin's encoder buffers are # sized max(full clip, one canvas-sized frame), so keyframe tasks carry no # extra cap. NOTE: true 1280x720 is impossible with this law (720 is not a # multiple of 32); the HD-shaped options are 1024x576 (exact 16:9), 1280x704 # or 1280x736 (through custom), and the model's native 1344x768 = 7:4. SIZE_MULT, MIN_SIDE = 32, 256 MAX_AREA, MAX_ASPECT = 1344 * 768, 4.0 # DaSiWa-style picking: a p-tier sets the SHORT side (raised to the 256 floor), # the aspect ratio computes the long side -- both snapped to 32-multiples and # scaled back under the canvas if needed. Tiers stop at 720p because a single # pass cannot exceed the canvas: DaSiWa's 900/1024/1080p presets are megapixel # budgets run as base pass + latent-upscaler second stage, which Radiance has # no equivalent of yet. TIERS = {"144p": 144, "240p": 240, "360p": 360, "480p": 480, "540p": 540, "576p": 576, "720p": 720} ASPECTS = ["5:4", "4:3", "3:2", "16:9", "2:1", "1:1", "1:2", "9:16", "2:3", "3:4", "4:5"] # The plain-text twin of the schema description below: shown inside the node when # the `help` widget is set to on (for frontends whose header ? glyph is missing). HELP_TEXT = """Radiance MiniMax -- input guide (no VRAM here; the model lives in the radiance server process). TASK decides which sockets are live; all others are IGNORED: t2va no media at all i2va image_1 = the FIRST frame l2va image_1 = the LAST frame (video grows back to it) fl2va image_1 = first frame, image_2 = last frame ref2va every media socket below MEDIA SOCKETS (wire Load Image / Video / Audio or generated media): image_1..9 reference images: identity/style (max 9) video_1..3 reference clips: motion/camera (max 3) video_audio_1..3 the SOUNDTRACK of video_N -- same number = same video; wire that video or this errors audio_1..3 STANDALONE reference audio: a voice/timbre to speak with. NOT a video soundtrack! ref2va: fill slots in order -- image_3 without image_2 is an error, the socket number IS the conditioning position. PROMPT: widget AND wire; a wired STRING (your LLM enhancer) wins over the typed text. The model was trained on the MiniMax format (subject_definitions / summary / retention_analysis / detailed_description,