Skip to content

Commit

Permalink
Fix .update() for gr.Radio() and gr.CheckboxGroup() (#5254)
Browse files Browse the repository at this point in the history
* fix dynamic -> interactive

* fix checks

* add changeset

* add changeset

* fix changeset

* fix linting issues

* Fix update choices

* add test

* fix'

* revert

* revert

* Delete curly-hands-carry.md

* add changeset

* add changeset

---------

Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 18, 2023
1 parent a773eaf commit c39f06e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-memes-clean.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Fix `.update()` for `gr.Radio()` and `gr.CheckboxGroup()`
5 changes: 5 additions & 0 deletions gradio/components/checkboxgroup.py
Expand Up @@ -133,6 +133,11 @@ def update(
interactive: bool | None = None,
visible: bool | None = None,
):
choices = (
None
if choices is None
else [c if isinstance(c, tuple) else (str(c), c) for c in choices]
)
return {
"choices": choices,
"label": label,
Expand Down
5 changes: 5 additions & 0 deletions gradio/components/radio.py
Expand Up @@ -135,6 +135,11 @@ def update(
interactive: bool | None = None,
visible: bool | None = None,
):
choices = (
None
if choices is None
else [c if isinstance(c, tuple) else (str(c), c) for c in choices]
)
return {
"choices": choices,
"label": label,
Expand Down
10 changes: 10 additions & 0 deletions test/test_components.py
Expand Up @@ -581,6 +581,16 @@ async def test_in_interface(self):
scores = (await iface.interpret(["b"]))[0]["interpretation"]
assert scores == [-2.0, None, 2.0]

def test_update(self):
update = gr.Radio.update(
choices=[("zeroth", ""), "first", "second"], label="ordinal"
)
assert update["choices"] == [
("zeroth", ""),
("first", "first"),
("second", "second"),
]


class TestDropdown:
def test_component_functions(self):
Expand Down

0 comments on commit c39f06e

Please sign in to comment.