Fixes gr.Interface.load() (#1436)

* format backend

* changes

Co-authored-by: Ali Abid <aabid94@gmail.com>
This commit is contained in:
Abubakar Abid 2022-05-31 22:35:33 -07:00 committed by GitHub
parent 7e796a3e17
commit 576bd227fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 10 deletions

View File

@ -382,7 +382,7 @@ if __name__ == "__main__":
![blocks_flipper interface](demo/blocks_flipper/screenshot.gif)
If you are interested in how Blocks works, [read its dedicated Guide](introduction_to_blocks).
If you are interested in how Blocks works, [read its dedicated Guide](https://gradio.app/introduction_to_blocks/).
### Sharing Demos 🌎

View File

@ -3580,9 +3580,7 @@ class Dataset(Clickable, Component):
visible (bool): If False, component will be hidden.
"""
Component.__init__(self, visible=visible, elem_id=elem_id, **kwargs)
self.components = (
components # [get_component_instance(c).unrender() for c in components]
)
self.components = [get_component_instance(c, render=False) for c in components]
self.type = type
self.headers = headers or [c.label for c in self.components]
self.samples = samples
@ -3694,13 +3692,18 @@ def component(cls_name: str) -> Component:
return obj
def get_component_instance(comp: str | dict | Component) -> Component:
def get_component_instance(comp: str | dict | Component, render=True) -> Component:
if isinstance(comp, str):
return component(comp)
component_obj = component(comp)
if not (render):
component_obj.unrender()
return component_obj
elif isinstance(comp, dict):
name = comp.pop("name")
component_cls = component_or_layout_class(name)
component_obj = component_cls(**comp)
if not (render):
component_obj.unrender()
return component_obj
elif isinstance(comp, Component):
return comp

View File

@ -201,8 +201,12 @@ class Interface(Blocks):
)
self.cache_examples = False
self.input_components = [get_component_instance(i).unrender() for i in inputs]
self.output_components = [get_component_instance(o).unrender() for o in outputs]
self.input_components = [
get_component_instance(i, render=False) for i in inputs
]
self.output_components = [
get_component_instance(o, render=False) for o in outputs
]
for component in self.input_components + self.output_components:
if not (

View File

@ -114,7 +114,6 @@
acc[next.id] = next;
return acc;
}, {} as { [id: number]: Component });
console.log(instance_map);
function load_component<T extends keyof typeof component_map>(
name: T
@ -132,7 +131,6 @@
async function walk_layout(node: LayoutNode) {
let instance = instance_map[node.id];
console.log(node.id, instance);
const _component = (await _component_map.get(instance.type)).component;
instance.component = _component.Component;
if (_component.modes.length > 1) {