mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-01 11:45:36 +08:00
update-components (#986)
- implement update function - create an example demo
This commit is contained in:
parent
1d3cb510bb
commit
6e1ccec1d0
17
demo/blocks_update/run.py
Normal file
17
demo/blocks_update/run.py
Normal 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()
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user