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

Fix gr.Group, container=False #4916

Merged
merged 16 commits into from Jul 17, 2023
2 changes: 1 addition & 1 deletion .config/playwright.config.js
Expand Up @@ -5,5 +5,5 @@ export default {
},
testMatch: /.*.spec.ts/,
testDir: "..",
globalSetup: "./playwright-setup.js",
globalSetup: "./playwright-setup.js"
};
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
* The `.change()` event is fixed in `Audio` so that fires when the component value is programmatically updated by [@abidlabs](https://github.com/abidlabs) in [PR 4793](https://github.com/gradio-app/gradio/pull/4793)
- Fixed bug where `gr.Video` could not preprocess urls by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4904](https://github.com/gradio-app/gradio/pull/4904)
- Fixed copy button rendering in API page on Safari by [@aliabid94](https://github.com/aliabid94) in [PR 4924](https://github.com/gradio-app/gradio/pull/4924)
- Fixed `gr.Group` and `container=False`. `container` parameter only available for `Textbox`, `Number`, and `Dropdown`, the only elements where it makes sense. By [@aliabid94](https://github.com/aliabid94) in [PR 4916](https://github.com/gradio-app/gradio/pull/4916)

## Other Changes:

Expand Down
2 changes: 1 addition & 1 deletion gradio/components/annotated_image.py
Expand Up @@ -46,7 +46,7 @@ def __init__(
color_map: dict[str, str] | None = None,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/audio.py
Expand Up @@ -56,7 +56,7 @@ def __init__(
type: Literal["numpy", "filepath"] = "numpy",
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/bar_plot.py
Expand Up @@ -58,7 +58,7 @@ def __init__(
caption: str | None = None,
interactive: bool | None = True,
label: str | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
aliabid94 marked this conversation as resolved.
Show resolved Hide resolved
scale: int | None = None,
min_width: int = 160,
Expand Down
10 changes: 9 additions & 1 deletion gradio/components/base.py
Expand Up @@ -133,7 +133,7 @@ def __init__(
value: Any = None,
label: str | None = None,
info: str | None = None,
show_label: bool = True,
show_label: bool | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to update the docstring to reflect that show_label=None falls back to the container param

container: bool = True,
scale: int | None = None,
min_width: int | None = None,
Expand All @@ -156,6 +156,12 @@ def __init__(

self.label = label
self.info = info
if not container:
if show_label:
warn_deprecation("show_label has no effect when container is False.")
show_label = False
if show_label is None:
show_label = True
self.show_label = show_label
self.container = container
if scale is not None and scale != round(scale):
Expand Down Expand Up @@ -366,6 +372,8 @@ def as_example(self, input_data):

class FormComponent:
def get_expected_parent(self) -> type[Form]:
if getattr(self, "container", None) is False:
return None
return Form


Expand Down
2 changes: 1 addition & 1 deletion gradio/components/chatbot.py
Expand Up @@ -42,7 +42,7 @@ def __init__(
*,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/checkbox.py
Expand Up @@ -40,7 +40,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/checkboxgroup.py
Expand Up @@ -42,7 +42,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/code.py
Expand Up @@ -57,7 +57,7 @@ def __init__(
lines: int = 5,
label: str | None = None,
interactive: bool | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/color_picker.py
Expand Up @@ -37,7 +37,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/dataframe.py
Expand Up @@ -55,7 +55,7 @@ def __init__(
overflow_row_behaviour: Literal["paginate", "show_ends"] = "paginate",
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
scale: int | None = None,
min_width: int = 160,
interactive: bool | None = None,
Expand Down
3 changes: 2 additions & 1 deletion gradio/components/dropdown.py
Expand Up @@ -50,7 +50,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down Expand Up @@ -155,6 +155,7 @@ def get_config(self):
"multiselect": self.multiselect,
"max_choices": self.max_choices,
"allow_custom_value": self.allow_custom_value,
"container": self.container,
**IOComponent.get_config(self),
}

Expand Down
2 changes: 1 addition & 1 deletion gradio/components/file.py
Expand Up @@ -51,7 +51,7 @@ def __init__(
type: Literal["file", "binary"] = "file",
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/gallery.py
Expand Up @@ -39,7 +39,7 @@ def __init__(
*,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/highlighted_text.py
Expand Up @@ -42,7 +42,7 @@ def __init__(
adjacent_separator: str = "",
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/html.py
Expand Up @@ -30,7 +30,7 @@ def __init__(
*,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
visible: bool = True,
elem_id: str | None = None,
elem_classes: list[str] | str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/image.py
Expand Up @@ -69,7 +69,7 @@ def __init__(
type: Literal["numpy", "pil", "filepath"] = "numpy",
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/json_component.py
Expand Up @@ -33,7 +33,7 @@ def __init__(
*,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/label.py
Expand Up @@ -42,7 +42,7 @@ def __init__(
num_top_classes: int | None = None,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/line_plot.py
Expand Up @@ -71,7 +71,7 @@ def __init__(
caption: str | None = None,
interactive: bool | None = True,
label: str | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/model3d.py
Expand Up @@ -40,7 +40,7 @@ def __init__(
clear_color: list[float] | None = None,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
3 changes: 2 additions & 1 deletion gradio/components/number.py
Expand Up @@ -49,7 +49,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down Expand Up @@ -127,6 +127,7 @@ def get_config(self):
"value": self.value,
"minimum": self.minimum,
"maximum": self.maximum,
"container": self.container,
**IOComponent.get_config(self),
}

Expand Down
2 changes: 1 addition & 1 deletion gradio/components/plot.py
Expand Up @@ -36,7 +36,7 @@ def __init__(
*,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/radio.py
Expand Up @@ -43,7 +43,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/scatter_plot.py
Expand Up @@ -87,7 +87,7 @@ def __init__(
interactive: bool | None = True,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/slider.py
Expand Up @@ -48,7 +48,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
3 changes: 2 additions & 1 deletion gradio/components/textbox.py
Expand Up @@ -59,7 +59,7 @@ def __init__(
label: str | None = None,
info: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down Expand Up @@ -134,6 +134,7 @@ def get_config(self):
"value": self.value,
"type": self.type,
"show_copy_button": self.show_copy_button,
"container": self.container,
**IOComponent.get_config(self),
}

Expand Down
2 changes: 1 addition & 1 deletion gradio/components/timeseries.py
Expand Up @@ -34,7 +34,7 @@ def __init__(
colors: list[str] | None = None,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/video.py
Expand Up @@ -60,7 +60,7 @@ def __init__(
width: int | None = None,
label: str | None = None,
every: float | None = None,
show_label: bool = True,
show_label: bool | None = None,
container: bool = True,
scale: int | None = None,
min_width: int = 160,
Expand Down
2 changes: 2 additions & 0 deletions gradio/layouts.py
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Literal

from gradio_client.documentation import document, set_documentation_group
Expand Down Expand Up @@ -295,6 +296,7 @@ def __init__(
visible: If False, box will be hidden.
elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
"""
warnings.warn("gr.Box is deprecated. Use gr.Group instead.", DeprecationWarning)
super().__init__(visible=visible, elem_id=elem_id, **kwargs)

def get_config(self):
Expand Down
2 changes: 1 addition & 1 deletion js/app/src/components/AnnotatedImage/AnnotatedImage.svelte
Expand Up @@ -19,7 +19,7 @@
export let height: number | undefined;
export let width: number | undefined;
export let color_map: Record<string, string>;
export let container: boolean = false;
export let container: boolean = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let root: string;
Expand Down
2 changes: 1 addition & 1 deletion js/app/src/components/Audio/Audio.svelte
Expand Up @@ -34,7 +34,7 @@
export let pending: boolean;
export let streaming: boolean;
export let root_url: null | string;
export let container = false;
export let container: boolean = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
Expand Down
2 changes: 1 addition & 1 deletion js/app/src/components/Checkbox/Checkbox.svelte
Expand Up @@ -12,7 +12,7 @@
export let label: string = "Checkbox";
export let info: string | undefined = undefined;
export let mode: "static" | "dynamic";
export let container: boolean = false;
export let container: boolean = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
Expand Down
2 changes: 1 addition & 1 deletion js/app/src/components/CheckboxGroup/CheckboxGroup.svelte
Expand Up @@ -10,7 +10,7 @@
export let value: Array<string> = [];
export let value_is_output: boolean = false;
export let choices: Array<string>;
export let container: boolean = false;
export let container: boolean = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let mode: "static" | "dynamic";
Expand Down
2 changes: 1 addition & 1 deletion js/app/src/components/ColorPicker/ColorPicker.svelte
Expand Up @@ -14,7 +14,7 @@
export let value: string;
export let value_is_output: boolean = false;
export let show_label: boolean;
export let container: boolean = false;
export let container: boolean = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
Expand Down
5 changes: 3 additions & 2 deletions js/app/src/components/Dropdown/Dropdown.svelte
Expand Up @@ -15,7 +15,7 @@
export let max_choices: number;
export let choices: Array<string>;
export let show_label: boolean;
export let container: boolean = false;
export let container: boolean = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
Expand All @@ -30,7 +30,7 @@
}
</script>

<Block {visible} {elem_id} {elem_classes} {container} {scale} {min_width}>
<Block {visible} {elem_id} {elem_classes} padding={container} allow_overflow={false} {scale} {min_width}>
<StatusTracker {...loading_status} />

<Dropdown
Expand All @@ -43,6 +43,7 @@
{info}
{show_label}
{allow_custom_value}
{container}
on:change
on:input
on:select
Expand Down