Load example from external Spaces#2594
Conversation
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2594-all-demos |
| block_config["props"].pop("type", None) | ||
| block_config["props"].pop("name", None) | ||
| style = block_config["props"].pop("style", None) | ||
| if block_config["props"].get("root_url") is None: |
There was a problem hiding this comment.
If the Space is already loading from another Space, it should use the root_url of the parent Space. This allows loading a chain of Spaces
|
|
||
| with Blocks(theme=config["theme"], css=config["theme"]) as blocks: | ||
| # ID 0 should be the root Blocks component | ||
| original_mapping[0] = Context.root_block or blocks |
There was a problem hiding this comment.
Fixing a different bug that was preventing gr.Interface.load() from working if a dataset had caching enabled
freddyaboulton
left a comment
There was a problem hiding this comment.
Thanks for the fix @abidlabs ! Looks good.
Noticed some weird behavior when trying to load a private space. Posting it here so you can review.
| else: | ||
| fns.append(None) | ||
| return gradio.Blocks.from_config(config, fns) | ||
| return gradio.Blocks.from_config(config, fns, iframe_url) |
There was a problem hiding this comment.
When loading a private space, the inputs are shown correctly but the outputs are.
Testing with this private space: https://huggingface.co/spaces/gradio/test-loading-examples-private
There was a problem hiding this comment.
Lol that's interesting. I get the same behavior as you the 2nd time -- everything but Model3D shows up. Nice catch, let me investigate
There was a problem hiding this comment.
This seems like a weird CORS issue and tbh I'm not sure what to do here. I think since this is a relatively niche use case (loading private Spaces, with (only?) the Model3D component), we can save for a future PR. I know @aliabid94 will be looking to CORS soon as well so flagging for your attention @aliabid94
There was a problem hiding this comment.
Sounds good with me. What makes you think it's a CORS issue?
| for target in targets: | ||
| event_method = getattr(original_mapping[target], trigger) | ||
| event_method(fn=fn, **dependency) | ||
| original_mapping[target].set_event_trigger( |
There was a problem hiding this comment.
How come we need to make this change?
There was a problem hiding this comment.
Because we define a "fake_event" that doesn't actually exist as an event method.
Also the less that we use methods like getattr() the better imo!
|
See my comments above @freddyaboulton, thanks for the review! |




gr.Blocks.load()orgr.Interface.load()now correctly loads examples from Spaces. You can test by running this:or a more complex example:
Loading more than 1 Space in one Blocks:
It is unfortunately not going to be possible to override examples when you load a gradio Interface or Blocks running 3.x. It is not possible to override any of the Interface properties (e.g. title) because we do not capture any reference to these Interface-specific properties. We instead load a generic Blocks that "happens" to look like an Interface. It might be possible to parse Interface-specific properties but it will be quite complex and I do not think the added complexity is worth it.
Fixes: #2554