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

Dropdown Component Updates #3211

Merged
merged 33 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
693f900
dropdown
dawoodkhan82 Feb 16, 2023
c003cca
Merge branch 'main' into dropdown
dawoodkhan82 Feb 18, 2023
497ed0b
more dropdown updates
dawoodkhan82 Feb 18, 2023
b7de906
dropdown styling + option visibility
dawoodkhan82 Feb 19, 2023
ef69968
Merge branch 'main' into dropdown
dawoodkhan82 Feb 19, 2023
c3f4ef7
changelog
dawoodkhan82 Feb 19, 2023
fcfa284
notebook
dawoodkhan82 Feb 19, 2023
8f3eed4
Merge branch 'main' into dropdown
abidlabs Feb 21, 2023
92fca9c
fix test
dawoodkhan82 Feb 22, 2023
a95c27d
Allow more image formats (#3225)
fienestar Feb 21, 2023
0320147
fix webcam mirroring (#3245)
pngwn Feb 21, 2023
e8f4787
Add `interactive=False` mode to `gr.Button` (#3266)
abidlabs Feb 21, 2023
5951938
LaTeX height fix (#3258)
abidlabs Feb 21, 2023
5d1bf57
accidentally added script (#3273)
abidlabs Feb 21, 2023
070e374
Adding a script to benchmark the queue (#3272)
abidlabs Feb 21, 2023
c32c629
Fix matplotlib image size (#3274)
freddyaboulton Feb 21, 2023
19d76b8
Add timeouts to queue messages (#3196)
freddyaboulton Feb 21, 2023
9e03ffe
icons
dawoodkhan82 Feb 22, 2023
263fb3f
separate options into component
dawoodkhan82 Feb 22, 2023
573d22e
formatting
dawoodkhan82 Feb 22, 2023
a6369ca
merge
dawoodkhan82 Feb 22, 2023
a7f157f
Merge branch 'main' into dropdown
dawoodkhan82 Feb 22, 2023
5197a4b
changelog
dawoodkhan82 Feb 22, 2023
56955a0
changelog
dawoodkhan82 Feb 22, 2023
0604b06
fix ui tests
dawoodkhan82 Feb 22, 2023
6362002
formatting again...
dawoodkhan82 Feb 22, 2023
d477f06
backend test fix
dawoodkhan82 Feb 23, 2023
bb60d5b
Merge branch 'main' into dropdown
dawoodkhan82 Feb 23, 2023
5241f63
format
dawoodkhan82 Feb 23, 2023
30be3cd
Merge branch 'main' into dropdown
abidlabs Feb 23, 2023
c1834ec
Merge branch 'main' into dropdown
abidlabs Feb 23, 2023
68403be
doc fixes
dawoodkhan82 Feb 23, 2023
a2eb90d
Merge branch 'main' into dropdown
dawoodkhan82 Feb 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Upcoming Release

## New Features:

### Dropdown Component Updates

The standard dropdown component now supports searching for choices. Also when `multiselect` is `True`, you can specify `max_choices` to set the maximum number of choices you want the user to be able to select from the dropdown component.

```python
gr.Dropdown(label="Multiselect Dropdown", choices=CHOICES, multiselect=True, max_choices=2),
dawoodkhan82 marked this conversation as resolved.
Show resolved Hide resolved
```
by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3211](https://github.com/gradio-app/gradio/pull/3211)

- Updated image upload component to accept all image formats, including lossless formats like .webp by [@fienestar](https://github.com/fienestar) in [PR 3225](https://github.com/gradio-app/gradio/pull/3225)
- Adds a disabled mode to the `gr.Button` component by setting `interactive=False` by [@abidlabs](https://github.com/abidlabs) in [PR 3266](https://github.com/gradio-app/gradio/pull/3266) and [PR 3288](https://github.com/gradio-app/gradio/pull/3288)
- Allow the setting of `brush_radius` for the `Image` component both as a default and via `Image.update()` by [@pngwn](https://github.com/pngwn) in [PR 3277](https://github.com/gradio-app/gradio/pull/3277)
Expand Down
2 changes: 1 addition & 1 deletion demo/kitchen_sink/run.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions demo/kitchen_sink/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def fn(
checkboxes,
radio,
dropdown,
multi_dropdown,
im1,
im2,
im3,
Expand Down Expand Up @@ -96,6 +97,7 @@ def fn(
gr.CheckboxGroup(label="CheckboxGroup", choices=CHOICES, value=CHOICES[0:2]),
gr.Radio(label="Radio", choices=CHOICES, value=CHOICES[2]),
gr.Dropdown(label="Dropdown", choices=CHOICES),
gr.Dropdown(label="Multiselect Dropdown (Max choice: 2)", choices=CHOICES, multiselect=True, max_choices=2),
gr.Image(label="Image"),
gr.Image(label="Image w/ Cropper", tool="select"),
gr.Image(label="Sketchpad", source="canvas"),
Expand Down Expand Up @@ -135,6 +137,7 @@ def fn(
["foo", "baz"],
"baz",
"bar",
["foo", "bar"],
os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
Expand Down
6 changes: 6 additions & 0 deletions gradio/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,7 @@ def __init__(
value: str | List[str] | Callable | None = None,
type: str = "value",
multiselect: bool | None = None,
max_choices: int | None = None,
label: str | None = None,
info: str | None = None,
every: float | None = None,
Expand All @@ -1219,6 +1220,7 @@ def __init__(
value: default value(s) selected in dropdown. If None, no value is selected by default. If callable, the function will be called whenever the app loads to set the initial value of the component.
type: Type of value to be returned by component. "value" returns the string of the choice selected, "index" returns the index of the choice selected.
multiselect: if True, multiple choices can be selected.
max_choices: maximum number of choices that can be selected. If None, no limit is enforced.
label: component name in interface.
info: additional component description.
every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
Expand All @@ -1238,6 +1240,9 @@ def __init__(
if multiselect:
if isinstance(value, str):
value = [value]
if not multiselect and max_choices is not None:
warnings.warn("Max choices is ignored when multiselect is False.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
warnings.warn("Max choices is ignored when multiselect is False.")
warnings.warn("The `max_choices` parameter is ignored when `multiselect` is False.")

self.max_choices = max_choices
self.test_input = self.choices[0] if len(self.choices) else None
self.interpret_by_tokens = False
IOComponent.__init__(
Expand All @@ -1259,6 +1264,7 @@ def get_config(self):
"choices": self.choices,
"value": self.value,
"multiselect": self.multiselect,
"max_choices": self.max_choices,
**IOComponent.get_config(self),
}

Expand Down
7 changes: 5 additions & 2 deletions test/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def test_component_functions(self):
assert dropdown_input.preprocess("a") == "a"
assert dropdown_input.postprocess("a") == "a"

dropdown_input_multiselect = gr.Dropdown(["a", "b", "c"], multiselect=True)
dropdown_input_multiselect = gr.Dropdown(["a", "b", "c"])
assert dropdown_input_multiselect.preprocess(["a", "c"]) == ["a", "c"]
assert dropdown_input_multiselect.postprocess(["a", "c"]) == ["a", "c"]
assert dropdown_input_multiselect.serialize(["a", "c"], True) == ["a", "c"]
Expand All @@ -572,6 +572,8 @@ def test_component_functions(self):
value=["a", "c"],
choices=["a", "b", "c"],
label="Select Your Inputs",
multiselect=True,
max_choices=2,
)
assert dropdown_input_multiselect.get_config() == {
"choices": ["a", "b", "c"],
Expand All @@ -584,7 +586,8 @@ def test_component_functions(self):
"visible": True,
"interactive": None,
"root_url": None,
"multiselect": None,
"multiselect": True,
"max_choices": 2,
}
with pytest.raises(ValueError):
gr.Dropdown(["a"], type="unknown")
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/app/src/components/Dropdown/Dropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
export let visible: boolean = true;
export let value: string | Array<string> = [];
export let multiselect: boolean = false;
export let max_choices: number;
export let choices: Array<string>;
export let show_label: boolean;
export let style: Styles = {};
Expand All @@ -30,6 +31,7 @@
bind:value
{choices}
{multiselect}
{max_choices}
{label}
{info}
{show_label}
Expand Down
12 changes: 8 additions & 4 deletions ui/packages/app/test/outbreak_forecast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ test("matplotlib", async ({ page }) => {
await mock_api(page, [[{ type: "matplotlib", plot: BASE64_PLOT_IMG }]]);
await page.goto("http://localhost:9876");

await page.getByLabel("Plot Type").selectOption("Matplotlib");
await page.getByLabel("Month").selectOption("January");
await page.getByLabel("Plot Type").click();
await page.getByRole("button", { name: "Matplotlib" }).click();
await page.getByLabel("Month").click();
await page.getByRole("button", { name: "January" }).click();
await page.getByLabel("Social Distancing?").check();

await Promise.all([
Expand All @@ -57,8 +59,10 @@ test("plotly", async ({ page }) => {
]);
await page.goto("http://localhost:9876");

await page.getByLabel("Plot Type").selectOption("Plotly");
await page.getByLabel("Month").selectOption("January");
await page.getByLabel("Plot Type").click();
await page.getByRole("button", { name: "Matplotlib" }).click();
await page.getByLabel("Month").click();
await page.getByRole("button", { name: "January" }).click();
await page.getByLabel("Social Distancing?").check();

await Promise.all([
Expand Down
3 changes: 2 additions & 1 deletion ui/packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"private": true,
"dependencies": {
"@gradio/atoms": "workspace:^0.0.1",
"@gradio/utils": "workspace:^0.0.1"
"@gradio/utils": "workspace:^0.0.1",
"@gradio/icons": "workspace:^0.0.1"
}
}
Loading