diff --git a/CHANGELOG.md b/CHANGELOG.md index 2317cd5fbc6c..3f09efc4a19b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ By [@aliabid94](https://github.com/aliabid94) in [PR 3466](https://github.com/gr ## Testing and Infrastructure Changes: - Pinned `pyright==1.1.298` for stability by [@abidlabs](https://github.com/abidlabs) in [PR 3475](https://github.com/gradio-app/gradio/pull/3475) +- Removed `IOComponent.add_interactive_to_config()` by [@space-nuko](https://github.com/space-nuko) in [PR 3476](https://github.com/gradio-app/gradio/pull/3476) - Removed `IOComponent.generate_sample()` by [@space-nuko](https://github.com/space-nuko) in [PR 3475](https://github.com/gradio-app/gradio/pull/3483) ## Breaking Changes: diff --git a/gradio/blocks.py b/gradio/blocks.py index a9a2914ef83c..cadd233d92ce 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -400,6 +400,9 @@ def postprocess_update_dict(block: Block, update_dict: Dict, postprocess: bool = update_dict = block.get_specific_update(update_dict) if update_dict.get("value") is components._Keywords.NO_VALUE: update_dict.pop("value") + interactive = update_dict.pop("interactive", None) + if interactive is not None: + update_dict["mode"] = "dynamic" if interactive else "static" prediction_value = delete_none(update_dict, skip_value=True) if "value" in prediction_value and postprocess: assert isinstance( diff --git a/gradio/components.py b/gradio/components.py index 9ee35398a10b..118b978c6350 100644 --- a/gradio/components.py +++ b/gradio/components.py @@ -209,12 +209,6 @@ def get_config(self): config["info"] = self.info return config - @staticmethod - def add_interactive_to_config(config, interactive): - if interactive is not None: - config["mode"] = "dynamic" if interactive else "static" - return config - @staticmethod def get_load_fn_and_initial_value(value): if callable(value): @@ -347,7 +341,7 @@ def update( interactive: bool | None = None, type: str | None = None, ): - updated_config = { + return { "lines": lines, "max_lines": max_lines, "placeholder": placeholder, @@ -356,9 +350,9 @@ def update( "visible": visible, "value": value, "type": type, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: str | None) -> str | None: """ @@ -552,14 +546,14 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "label": label, "show_label": show_label, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: float | None) -> float | None: """ @@ -745,7 +739,7 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "minimum": minimum, "maximum": maximum, "step": step, @@ -754,9 +748,9 @@ def update( "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def postprocess(self, y: float | None) -> float | None: """ @@ -880,15 +874,15 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def get_interpretation_neighbors(self, x): return [not x], {} @@ -1000,16 +994,16 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "choices": choices, "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: List[str]) -> List[str] | List[int]: """ @@ -1182,16 +1176,16 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "choices": choices, "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: str | None) -> str | int | None: """ @@ -1351,16 +1345,16 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "choices": choices, "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess( self, x: str | List[str] @@ -1543,16 +1537,16 @@ def update( visible: bool | None = None, brush_radius: int | None = None, ): - updated_config = { + return { "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, "brush_radius": brush_radius, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def _format_image( self, im: _Image.Image | None @@ -1892,16 +1886,16 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "source": source, "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: Dict[str, str] | None) -> str | None: """ @@ -2114,16 +2108,16 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "source": source, "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess( self, x: Dict[str, Any] | None @@ -2434,15 +2428,15 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess( self, x: List[Dict[str, Any]] | None @@ -2699,7 +2693,7 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "max_rows": max_rows, "max_cols": max_cols, "label": label, @@ -2707,9 +2701,9 @@ def update( "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: DataframeData): """ @@ -2915,16 +2909,16 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "colors": colors, "label": label, "show_label": show_label, "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: Dict | None) -> pd.DataFrame | None: """ @@ -3075,13 +3069,13 @@ def update( visible: bool | None = None, interactive: bool | None = None, ): - updated_config = { + return { "variant": variant, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def style( self, @@ -3179,13 +3173,13 @@ def update( interactive: bool | None = None, visible: bool | None = None, ): - updated_config = { + return { "interactive": interactive, "visible": visible, "value": value, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess( self, x: List[Dict[str, Any]] | None @@ -3338,14 +3332,14 @@ def update( visible: bool | None = None, interactive: bool | None = None, ): - updated_config = { + return { "value": value, "label": label, "show_label": show_label, "visible": visible, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def preprocess(self, x: str | None) -> str | None: """ @@ -3501,7 +3495,7 @@ def update( # e.g. no background default state. elif color is None: color = "transparent" - updated_config = { + return { "label": label, "show_label": show_label, "visible": visible, @@ -3509,7 +3503,6 @@ def update( "color": color, "__type__": "update", } - return updated_config def style( self, @@ -5614,15 +5607,15 @@ def update( language: str | None = None, interactive: bool | None = True, ): - updated_config = { + return { "label": label, "show_label": show_label, "visible": visible, "value": value, "language": language, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) def style(self): return self diff --git a/guides/06_other-tutorials/creating-a-new-component.md b/guides/06_other-tutorials/creating-a-new-component.md index 6159e37ca0e2..c08d4d2767e8 100644 --- a/guides/06_other-tutorials/creating-a-new-component.md +++ b/guides/06_other-tutorials/creating-a-new-component.md @@ -79,14 +79,14 @@ class ColorPicker(Changeable, Submittable, IOComponent): visible: Optional[bool] = None, interactive: Optional[bool] = None, ): - updated_config = { + return { "value": value, "label": label, "show_label": show_label, "visible": visible, + "interactive": interactive, "__type__": "update", } - return IOComponent.add_interactive_to_config(updated_config, interactive) # Input Functionalities def preprocess(self, x: str | None) -> Any: diff --git a/test/test_blocks.py b/test/test_blocks.py index d279a6cbc595..b2c63179ed9b 100644 --- a/test/test_blocks.py +++ b/test/test_blocks.py @@ -46,16 +46,9 @@ def captured_output(): class TestBlocksMethods: maxDiff = None - def test_set_share(self): + def test_set_share_is_false_by_default(self): with gr.Blocks() as demo: - # self.share is False when instantiating the class - assert not demo.share - # default is False, if share is None - demo.share = None assert not demo.share - # if set to True, it doesn't change - demo.share = True - assert demo.share @patch("gradio.networking.setup_tunnel") @patch("gradio.utils.colab_check") @@ -449,6 +442,7 @@ def test_get_load_events(self, io_components): class TestBlocksPostprocessing: def test_blocks_do_not_filter_none_values_from_updates(self, io_components): + io_components = [ c() for c in io_components @@ -575,7 +569,6 @@ def generic_update(): for fn_index in range(2): output = await demo.process_api(fn_index, [], state={}) assert output["data"][0] == { - "interactive": True, "__type__": "update", "mode": "dynamic", } @@ -888,11 +881,10 @@ def test_with_update(self): "label": None, "show_label": None, "type": None, - "type": None, + "interactive": False, "visible": None, "value": gr.components._Keywords.NO_VALUE, - "__type__": "update", - "mode": "static", + "__type__": "update" } specific_update = gr.Textbox.get_specific_update( @@ -905,10 +897,10 @@ def test_with_update(self): "label": None, "show_label": None, "type": None, + "interactive": True, "visible": None, "value": gr.components._Keywords.NO_VALUE, - "__type__": "update", - "mode": "dynamic", + "__type__": "update" } def test_with_generic_update(self): @@ -926,7 +918,6 @@ def test_with_generic_update(self): "show_label": None, "visible": True, "value": "test.mp4", - "mode": "dynamic", "interactive": True, "__type__": "update", }