mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Fix returning copies of a component instance from a prediction function (#6940)
* add test * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
de603edfe2
commit
c00da89c3e
5
.changeset/tangy-spoons-hug.md
Normal file
5
.changeset/tangy-spoons-hug.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Fix returning copies of a component instance from a prediction function
|
@ -1429,7 +1429,7 @@ Received outputs:
|
||||
)
|
||||
|
||||
if isinstance(prediction_value, Block):
|
||||
prediction_value = prediction_value.constructor_args
|
||||
prediction_value = prediction_value.constructor_args.copy()
|
||||
prediction_value["__type__"] = "update"
|
||||
if utils.is_update(prediction_value):
|
||||
if output_id in state:
|
||||
|
@ -1603,3 +1603,24 @@ def test_emptry_string_api_name_gets_set_as_fn_name():
|
||||
t1.change(test_fn, t1, t2, api_name="")
|
||||
|
||||
assert demo.dependencies[0]["api_name"] == "test_fn"
|
||||
|
||||
|
||||
def test_blocks_postprocessing_with_copies_of_component_instance():
|
||||
# Test for: https://github.com/gradio-app/gradio/issues/6608
|
||||
with gr.Blocks() as demo:
|
||||
chatbot = gr.Chatbot()
|
||||
chatbot2 = gr.Chatbot()
|
||||
chatbot3 = gr.Chatbot()
|
||||
clear = gr.Button("Clear")
|
||||
|
||||
def clear_func():
|
||||
return tuple([gr.Chatbot(value=[])] * 3)
|
||||
|
||||
clear.click(
|
||||
fn=clear_func, outputs=[chatbot, chatbot2, chatbot3], api_name="clear"
|
||||
)
|
||||
|
||||
assert (
|
||||
demo.postprocess_data(0, [gr.Chatbot(value=[])] * 3, None)
|
||||
== [{"value": [], "__type__": "update"}] * 3
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user