Skip to content

Commit bc5fccf

Browse files
Allow gr.load to work inside gr.Blocks automatically (#8579)
* load-in-blocks * allow gr.load inside gr.Blocks * add changeset * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 7833749 commit bc5fccf

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.changeset/quick-dolls-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gradio": patch
3+
---
4+
5+
fix:Allow `gr.load` to work inside `gr.Blocks` automatically

gradio/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ def iterate_over_children(children_list):
11811181

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

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

@@ -1256,7 +1256,7 @@ def iterate_over_children(children_list):
12561256
)
12571257
for t in targets
12581258
]
1259-
dependency = blocks.default_config.set_event_trigger(
1259+
dependency = root_block.default_config.set_event_trigger(
12601260
targets=targets, fn=fn, **dependency
12611261
)[0]
12621262
if first_dependency is None:

test/test_external.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,9 @@ def test_load_custom_component():
505505
"test/test_files/sample_file.pdf", "What does this say?", api_name="predict"
506506
)
507507
assert isinstance(output, str)
508+
509+
510+
def test_load_inside_blocks():
511+
demo = gr.load("spaces/abidlabs/en2fr")
512+
output = demo("Hello")
513+
assert isinstance(output, str)

0 commit comments

Comments
 (0)