Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow gr.load to work inside gr.Blocks automatically #8579

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quick-dolls-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Allow `gr.load` to work inside `gr.Blocks` automatically
4 changes: 2 additions & 2 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ def iterate_over_children(children_list):

with Blocks(theme=theme) as blocks:
# ID 0 should be the root Blocks component
original_mapping[0] = Context.root_block or blocks
original_mapping[0] = root_block = Context.root_block or blocks

iterate_over_children(config["layout"]["children"])

Expand Down Expand Up @@ -1256,7 +1256,7 @@ def iterate_over_children(children_list):
)
for t in targets
]
dependency = blocks.default_config.set_event_trigger(
dependency = root_block.default_config.set_event_trigger(
targets=targets, fn=fn, **dependency
)[0]
if first_dependency is None:
Expand Down
6 changes: 6 additions & 0 deletions test/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,9 @@ def test_load_custom_component():
"test/test_files/sample_file.pdf", "What does this say?", api_name="predict"
)
assert isinstance(output, str)


def test_load_inside_blocks():
demo = gr.load("spaces/abidlabs/en2fr")
output = demo("Hello")
assert isinstance(output, str)