Fix bug preventing layout components to be used as custom components (#7050)

This commit is contained in:
Freddy Boulton 2024-01-19 02:02:08 +05:30 committed by GitHub
parent 45df1ce5d7
commit a336508646
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Fix bug preventing layout components to be used as custom components

View File

@ -618,9 +618,9 @@ class Blocks(BlockContext, BlocksEvents, metaclass=BlocksMeta):
self.queue()
def get_component(self, id: int) -> Component:
def get_component(self, id: int) -> Component | BlockContext:
comp = self.blocks[id]
assert isinstance(comp, components.Component), f"{comp}"
assert isinstance(comp, (components.Component, BlockContext)), f"{comp}"
return comp
@property
@ -2307,8 +2307,10 @@ Received outputs:
# The config has the most specific API info (taking into account the parameters
# of the component), so we use that if it exists. Otherwise, we fallback to the
# Serializer's API info.
info = self.get_component(component["id"]).api_info()
example = self.get_component(component["id"]).example_inputs()
comp = self.get_component(component["id"])
assert isinstance(comp, components.Component)
info = comp.api_info()
example = comp.example_inputs()
python_type = client_utils.json_schema_to_python_type(info)
dependency_info["parameters"].append(
{
@ -2335,8 +2337,10 @@ Received outputs:
if self.blocks[component["id"]].skip_api:
continue
label = component["props"].get("label", f"value_{o}")
info = self.get_component(component["id"]).api_info()
example = self.get_component(component["id"]).example_inputs()
comp = self.get_component(component["id"])
assert isinstance(comp, components.Component)
info = comp.api_info()
example = comp.example_inputs()
python_type = client_utils.json_schema_to_python_type(info)
dependency_info["returns"].append(
{