Allow Blocks instances to be used like a Block in other Blocks#919
Conversation
| flagging_dir=interface.flagging_dir, | ||
| ) | ||
|
|
||
|
|
There was a problem hiding this comment.
This seems not the right way to do this. Why can't you just call interface.render() instead of creating a new Interface?
Also I'm a little skeptical we should even create TabbedInterface, instead of allowing users to naturally explore Blocks as they want more customizability.
There was a problem hiding this comment.
Why can't you just call interface.render()
There's a few Interface kwargs that don't make sense to have within this context. For example, theme. So I just decided to pick the kwargs that make sense to include here.
Also I'm a little skeptical we should even create TabbedInterface, instead of allowing users to naturally explore Blocks as they want more customizability
Open to discussion about this. We should keep in mind that we've heard directly from several users that they want something like this rather than having to delve into the lower-level Blocks API. E.g. #690 (comment)
|
|
||
| class Block: | ||
| def __init__(self): | ||
| def __init__(self, without_rendering=False): |
There was a problem hiding this comment.
is it possible that instead of using "without_rendering", it just checks to see if its within a BlockContext and only calls render if that's the case?
There was a problem hiding this comment.
That doesn't work. Consider the following example:
with gr.Blocks() as bl:
with gr.Tabs():
with gr.TabItem("Text"):
gr.Interface(lambda x:x, "textbox", "textbox")
with gr.TabItem("Image"):
gr.Interface(lambda x:x, "image", "image")
bl.launch()Inside the Interface class, you create Component objects once, and then render them later.
Create components:
Line 182 in 5c44ae3
Render:
Line 496 in 5c44ae3
In this case, both statements are inside a BlockContext (the outer level Blocks bl), so the component would end up getting rendered twice. That's why we need to explicitly escape the context.
|
I'm going to remove |
|
Lgtm |
This PR does a number of things:
demo/xray_blocks/run.pyto see the difference)So that we can do things like this:
TabbedInterfaceabstraction to make the above easier. Just a rough draft, feedback on naming and API welcome here