update-components (#986)

- implement update function
- create an example demo
This commit is contained in:
Ömer Faruk Özdemir 2022-04-13 14:57:42 +03:00 committed by GitHub
parent 1d3cb510bb
commit 6e1ccec1d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

17
demo/blocks_update/run.py Normal file
View File

@ -0,0 +1,17 @@
from gradio import Dropdown, Blocks, Slider
def update_dropdown_choices(val):
if val < 50:
opts = ["fail", "repeat"]
else:
opts = ["succeed", "repeat"]
return Dropdown.update(choices=opts)
with Blocks() as block:
s = Slider(default_value=0, minimum=0, maximum=100)
d = Dropdown(choices=["fake", "choices", "exist"])
s.change(fn=update_dropdown_choices, inputs=[s], outputs=[d])
block.launch()

View File

@ -209,6 +209,17 @@ class Component(Block):
"""
return x
@staticmethod
def update(**kwargs) -> dict:
"""
Updates component parameters
@param kwargs: Updating component parameters
@return: Updated component parameters
"""
kwargs["__type__"] = "update"
return kwargs
class Textbox(Component):
"""