最近需要用到Gradio的dropdown的控件,但是里面的默认值需要随着一些操作而改变,网上查了好久才有答案,这里给出一个示例,让大家少走弯路哈。
import gradio as gr
def Dropdown_list(x):
new_options = [*options, x + " Remastered", x + ": The Remake", x + ": Game of the Year Edition", x + " Steelbook Edition"]
return gr.Dropdown.update(choices=new_options)
demo = gr.Blocks()
options = ['Placeholder A', 'Placeholder B', 'Placeholder C']
with demo:
text_options = gr.Dropdown(options, label="Top 5 options")
b2 = gr.Button("Provide Additional options")
b2.click(Dropdown_list, inputs=text_input, outputs=text_options)
参考文献
How to update the gr.Dropdown() block in Gradio Blocks