mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
17 lines
501 B
Python
17 lines
501 B
Python
|
import gradio as gr
|
||
|
|
||
|
with gr.Blocks() as demo:
|
||
|
cart = gr.State([])
|
||
|
items_to_add = gr.CheckboxGroup(["Cereal", "Milk", "Orange Juice", "Water"])
|
||
|
|
||
|
def add_items(new_items, previous_cart):
|
||
|
cart = previous_cart + new_items
|
||
|
return cart
|
||
|
|
||
|
gr.Button("Add Items").click(add_items, [items_to_add, cart], cart)
|
||
|
|
||
|
cart_size = gr.Number(label="Cart Size")
|
||
|
gr.Button("Get Cart Size").click(lambda cart: len(cart), cart, cart_size)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
demo.launch()
|