mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Use updated component in postprocess()
(#7402)
* component update * add changeset * add test * lint * refactor --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
5b1ab3727c
commit
fa8225d24d
5
.changeset/blue-walls-flash.md
Normal file
5
.changeset/blue-walls-flash.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Use updated component in `postprocess()`
|
@ -1449,7 +1449,10 @@ Received outputs:
|
||||
raise InvalidComponentError(
|
||||
f"{block.__class__} Component with id {output_id} not a valid output component."
|
||||
)
|
||||
if output_id in state:
|
||||
block = state[output_id]
|
||||
prediction_value = block.postprocess(prediction_value)
|
||||
|
||||
outputs_cached = processing_utils.move_files_to_cache(
|
||||
prediction_value,
|
||||
block, # type: ignore
|
||||
|
@ -18,7 +18,7 @@ import numpy as np
|
||||
import pytest
|
||||
import uvicorn
|
||||
from fastapi.testclient import TestClient
|
||||
from gradio_client import media_data
|
||||
from gradio_client import Client, media_data
|
||||
from PIL import Image
|
||||
|
||||
import gradio as gr
|
||||
@ -823,6 +823,26 @@ class TestStateHolder:
|
||||
"error" not in session_1.json()
|
||||
) # no error because sesssion 1 block config was lost when session 3 was added
|
||||
|
||||
def test_state_holder_is_used_in_postprocess(self, connect):
|
||||
with gr.Blocks() as demo:
|
||||
dropdown = gr.Dropdown(label="list", choices=["Choice 1"], interactive=True)
|
||||
button = gr.Button("Get dropdown value")
|
||||
button2 = gr.Button("Convert dropdown to multiselect")
|
||||
button.click(
|
||||
lambda x: x, inputs=dropdown, outputs=dropdown, api_name="predict"
|
||||
)
|
||||
button2.click(
|
||||
lambda: gr.Dropdown(multiselect=True),
|
||||
outputs=dropdown,
|
||||
api_name="set_multiselect",
|
||||
)
|
||||
|
||||
client: Client
|
||||
with connect(demo) as client:
|
||||
assert client.predict("Choice 1", api_name="/predict") == "Choice 1"
|
||||
client.predict(api_name="/set_multiselect")
|
||||
assert client.predict("Choice 1", api_name="/predict") == ["Choice 1"]
|
||||
|
||||
|
||||
class TestCallFunction:
|
||||
@pytest.mark.asyncio
|
||||
|
Loading…
x
Reference in New Issue
Block a user