Allow Spaces with .success() to be gr.load-ed (#8242)

* fix success in gr.load

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Abubakar Abid 2024-05-08 19:34:23 -05:00 committed by GitHub
parent 6ee1f1f721
commit 05fe4918c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Allow Spaces with `.success()` to be `gr.load`-ed

View File

@ -990,7 +990,10 @@ class Blocks(BlockContext, BlocksEvents, metaclass=BlocksMeta):
# 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"

View File

@ -82,7 +82,7 @@ class TestBlocksMethods:
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}/"
@ -90,6 +90,19 @@ class TestBlocksMethods:
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}!")