Skip to content

Commit

Permalink
Allow Spaces with .success() to be gr.load-ed (#8242)
Browse files Browse the repository at this point in the history
* fix success in gr.load

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot committed May 9, 2024
1 parent 6ee1f1f commit 05fe491
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/social-tigers-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Allow Spaces with `.success()` to be `gr.load`-ed
5 changes: 4 additions & 1 deletion gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,10 @@ def iterate_over_children(children_list):
# This assumes that you cannot combine multiple .then() events in a single
# gr.on() event, which is true for now. If this changes, we will need to
# update this code.
if not isinstance(_targets[0], int) and _targets[0][1] == "then":
if not isinstance(_targets[0], int) and _targets[0][1] in [
"then",
"success",
]:
if len(_targets) != 1:
raise ValueError(
"This logic assumes that .then() events are not combined with other events in a single gr.on() event"
Expand Down
15 changes: 14 additions & 1 deletion test/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,27 @@ def update(name):
gr.Image(height=54, width=240)

config1 = demo1.get_config_file()
demo2 = gr.Blocks.from_config(config1, [update], "https://fake.hf.space")
demo2 = gr.Blocks.from_config(config1, [update], fake_url)

for component in config1["components"]:
component["props"]["proxy_url"] = f"{fake_url}/"
config2 = demo2.get_config_file()

assert assert_configs_are_equivalent_besides_ids(config1, config2)

def test_load_config_with_sucess(self):
fake_url = "https://fake.hf.space"
with gr.Blocks() as demo1:
t1 = gr.Textbox()
t2 = gr.Textbox()
t3 = gr.Textbox()
t4 = gr.Textbox()
t1.change(lambda x: x, t1, t2).then(lambda x: x, t2, t3).success(
lambda x: x, t3, t4
)
config1 = demo1.get_config_file()
gr.Blocks.from_config(config1, [lambda x: x] * 3, fake_url)

def test_partial_fn_in_config(self):
def greet(name, formatter):
return formatter(f"Hello {name}!")
Expand Down

0 comments on commit 05fe491

Please sign in to comment.