gradio/demo/variable_outputs/run.py
Abubakar Abid f062c7e1fd
Adds a demo / information about how to create demos with variable #s of outputs (#3127)
* added demo

* added to guide

* changelog

* notebooks

* update demo
2023-02-06 11:38:54 -08:00

20 lines
524 B
Python

import gradio as gr
max_textboxes = 10
def variable_outputs(k):
k = int(k)
return [gr.Textbox.update(visible=True)]*k + [gr.Textbox.update(visible=False)]*(max_textboxes-k)
with gr.Blocks() as demo:
s = gr.Slider(1, max_textboxes, value=max_textboxes, step=1, label="How many textboxes to show:")
textboxes = []
for i in range(max_textboxes):
t = gr.Textbox(f"Textbox {i}")
textboxes.append(t)
s.change(variable_outputs, s, textboxes)
if __name__ == "__main__":
demo.launch()