Description
When combining multiple real GradioNode instances using the | operator to create a ChoiceNode, the resulting node sometimes exposes no input ports, causing graph validation to fail.
Steps to Reproduce
- Create two or more
GradioNode instances that connect to real HuggingFace Spaces
- Combine them with the
| operator: choice = variant_a | variant_b
- Try to use the
ChoiceNode in a graph where downstream nodes depend on its outputs
Expected Behavior
The ChoiceNode should expose the union of all variants' input ports (similar to how it handles output ports), allowing edges to be created and graph validation to pass.
Actual Behavior
The ChoiceNode._input_ports is empty, causing graph validation to fail when trying to connect inputs.
Current Workaround
Manually merge variant registries into the ChoiceNode:
def _merge_variant_registry_into_choice(choice):
variants = getattr(choice, "_variants", None)
if not variants:
return choice
if not hasattr(choice, "_input_ports"):
choice._input_ports = []
if not hasattr(choice, "_input_components"):
choice._input_components = {}
if not hasattr(choice, "_fixed_inputs"):
choice._fixed_inputs = {}
if not hasattr(choice, "_port_connections"):
choice._port_connections = {}
for v in variants:
for p in getattr(v, "_input_ports", []):
if p not in choice._input_ports:
choice._input_ports.append(p)
choice._input_components.update(getattr(v, "_input_components", {}))
choice._fixed_inputs.update(getattr(v, "_fixed_inputs", {}))
choice._port_connections.update(getattr(v, "_port_connections", {}))
return choice
def safe_patch_choice(choice):
variants = getattr(choice, "_variants", None)
if not variants:
return choice
exposed_ports = getattr(choice, "_input_ports", None)
if exposed_ports and len(exposed_ports) > 0:
return choice
print("[SAFE PATCH] ChoiceNode exposes no input ports → merging variant registries.")
return _merge_variant_registry_into_choice(choice)
# Usage:
music_choice = variant_a | variant_b | variant_c
safe_patch_choice(music_choice)
Suggested Fix
Update ChoiceNode.__init__ to also compute the union of input ports, input components, and fixed inputs from all variants (similar to how _compute_union_output_ports works for outputs).
Reference
Description
When combining multiple real
GradioNodeinstances using the|operator to create aChoiceNode, the resulting node sometimes exposes no input ports, causing graph validation to fail.Steps to Reproduce
GradioNodeinstances that connect to real HuggingFace Spaces|operator:choice = variant_a | variant_bChoiceNodein a graph where downstream nodes depend on its outputsExpected Behavior
The
ChoiceNodeshould expose the union of all variants' input ports (similar to how it handles output ports), allowing edges to be created and graph validation to pass.Actual Behavior
The
ChoiceNode._input_portsis empty, causing graph validation to fail when trying to connect inputs.Current Workaround
Manually merge variant registries into the
ChoiceNode:Suggested Fix
Update
ChoiceNode.__init__to also compute the union of input ports, input components, and fixed inputs from all variants (similar to how_compute_union_output_portsworks for outputs).Reference