From 7ebe79a9878653faa6be9e236d066afe7227e7a1 Mon Sep 17 00:00:00 2001 From: Freddy Boulton Date: Mon, 16 Jan 2023 18:46:00 +0100 Subject: [PATCH] Fix interpretation events (#2993) * Fix interpretation + test * Changelog * Empty * Fix test * Handle None case Co-authored-by: Abubakar Abid * lint Co-authored-by: Abubakar Abid --- CHANGELOG.md | 1 + gradio/interface.py | 3 +-- test/test_interfaces.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 295cb363da..07e8beb5e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/gradio/interface.py b/gradio/interface.py index 8f93b1a557..72e3851082 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -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, ) diff --git a/test/test_interfaces.py b/test/test_interfaces.py index 9468922760..061781d77e 100644 --- a/test/test_interfaces.py +++ b/test/test_interfaces.py @@ -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)