Skip to content

Commit

Permalink
Allow gr.load to work inside gr.Blocks automatically (#8579)
Browse files Browse the repository at this point in the history
* load-in-blocks

* allow gr.load inside gr.Blocks

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot committed Jun 20, 2024
1 parent 7833749 commit bc5fccf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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)

0 comments on commit bc5fccf

Please sign in to comment.