Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IOComponent.add_interactive_to_config #3476

Merged
merged 16 commits into from Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions gradio/blocks.py
Expand Up @@ -399,6 +399,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.get("interactive")
space-nuko marked this conversation as resolved.
Show resolved Hide resolved
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(
Expand Down
77 changes: 35 additions & 42 deletions gradio/components.py
Expand Up @@ -215,12 +215,6 @@ def generate_sample(self) -> Any:
"""
pass

@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):
Expand Down Expand Up @@ -353,7 +347,7 @@ def update(
interactive: bool | None = None,
type: str | None = None,
):
updated_config = {
return {
"lines": lines,
"max_lines": max_lines,
"placeholder": placeholder,
Expand All @@ -362,9 +356,9 @@ def update(
"visible": visible,
"value": value,
"type": type,
"interactive": interactive,
"__type__": "update",
}
return IOComponent.add_interactive_to_config(updated_config, interactive)

def generate_sample(self) -> str:
return "Hello World"
Expand Down Expand Up @@ -561,14 +555,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:
"""
Expand Down Expand Up @@ -757,7 +751,7 @@ def update(
interactive: bool | None = None,
visible: bool | None = None,
):
updated_config = {
return {
"minimum": minimum,
"maximum": maximum,
"step": step,
Expand All @@ -766,9 +760,9 @@ def update(
"interactive": interactive,
"visible": visible,
"value": value,
"interactive": interactive,
"__type__": "update",
}
return IOComponent.add_interactive_to_config(updated_config, interactive)

def generate_sample(self) -> float:
return self.maximum
Expand Down Expand Up @@ -895,15 +889,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 generate_sample(self):
return True
Expand Down Expand Up @@ -1018,16 +1012,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 generate_sample(self):
return self.choices
Expand Down Expand Up @@ -1203,16 +1197,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 generate_sample(self):
return self.choices[0]
Expand Down Expand Up @@ -1375,16 +1369,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 generate_sample(self):
return self.choices[0]
Expand Down Expand Up @@ -1570,16 +1564,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
Expand Down Expand Up @@ -1922,16 +1916,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:
"""
Expand Down Expand Up @@ -2148,16 +2142,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
Expand Down Expand Up @@ -2471,15 +2465,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
Expand Down Expand Up @@ -2739,17 +2733,17 @@ def update(
interactive: bool | None = None,
visible: bool | None = None,
):
updated_config = {
return {
"max_rows": max_rows,
"max_cols": max_cols,
"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: DataframeData):
"""
Expand Down Expand Up @@ -2958,16 +2952,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:
"""
Expand Down Expand Up @@ -3124,13 +3118,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,
Expand Down Expand Up @@ -3228,13 +3222,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
Expand Down Expand Up @@ -3390,14 +3384,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:
"""
Expand Down Expand Up @@ -3556,15 +3550,14 @@ 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,
"value": value,
"color": color,
"__type__": "update",
}
return updated_config

def style(
self,
Expand Down Expand Up @@ -5675,15 +5668,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
Expand Down
4 changes: 2 additions & 2 deletions guides/06_other-tutorials/creating-a-new-component.md
Expand Up @@ -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:
Expand Down