Fix .update() for gr.Radio() and gr.CheckboxGroup() (#5254)

* 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>
This commit is contained in:
Abubakar Abid 2023-08-18 07:58:33 -07:00 committed by GitHub
parent a773eaf750
commit c39f06e16b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Fix `.update()` for `gr.Radio()` and `gr.CheckboxGroup()`

View File

@ -133,6 +133,11 @@ class CheckboxGroup(
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,

View File

@ -135,6 +135,11 @@ class Radio(
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,

View File

@ -581,6 +581,16 @@ class TestRadio:
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):