Spaces:
Runtime error
Runtime error
File size: 661 Bytes
95eeeb2 cd3f48f 95eeeb2 f0d419c 95eeeb2 f0d419c 95eeeb2 f0d419c 95eeeb2 f0d419c 95eeeb2 f0d419c 95eeeb2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import gradio as gr
from pprint import pprint
def update_list(current_list):
if not current_list:
current_list = []
new_item = f"Item {len(current_list) + 1}"
current_list.append(new_item)
return current_list
with gr.Blocks() as demo:
with gr.Row():
button = gr.Button("Add Item")
radio = gr.Radio(label="Items List", choices=[])
state = gr.State([]) # Initialize state
# When button is clicked, update the list
button.click(fn=update_list, inputs=state, outputs=state)
# Update the radio options when the state changes
state.change(fn=lambda x: x, inputs=state, outputs=radio)
demo.launch() |