Fix interpretation events (#2993)

* Fix interpretation + test

* Changelog

* Empty

* Fix test

* Handle None case

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* lint

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Freddy Boulton 2023-01-16 18:46:00 +01:00 committed by GitHub
parent 5c32ba31ba
commit 7ebe79a987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -4,6 +4,7 @@
No changes to highlight.
## Bug Fixes:
* Fixes bug where interpretation event was not configured correctly by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2993](https://github.com/gradio-app/gradio/pull/2993)
* Fix relative import bug in reload mode by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2992](https://github.com/gradio-app/gradio/pull/2992)
## Documentation Changes:

View File

@ -706,8 +706,7 @@ class Interface(Blocks):
interpretation_btn.click(
self.interpret_func,
inputs=self.input_components + self.output_components,
outputs=interpretation_set
or [] + [input_component_column, interpret_component_column], # type: ignore
outputs=(interpretation_set or []) + [input_component_column, interpret_component_column], # type: ignore
preprocess=False,
)

View File

@ -238,6 +238,34 @@ class TestInterfaceInterpretation:
interpretation="default",
)
interpretation_id = None
for c in iface.config["components"]:
if c["props"].get("value") == "Interpret" and c.get("type") == "button":
interpretation_id = c["id"]
# Make sure the event is configured correctly.
interpretation_dep = next(
d
for d in iface.config["dependencies"]
if d["targets"] == [interpretation_id]
)
interpretation_comps = [
c["id"]
for c in iface.config["components"]
if c.get("type") == "interpretation"
]
interpretation_columns = [
c["id"]
for c in iface.config["components"]
if c.get("type") == "column" and c["props"].get("variant") == "default"
]
assert sorted(interpretation_dep["outputs"]) == sorted(
interpretation_comps + interpretation_columns
)
assert sorted(interpretation_dep["inputs"]) == sorted(
[c._id for c in iface.input_components + iface.output_components]
)
app, _, _ = iface.launch(prevent_thread_lock=True)
client = TestClient(app)