import gradio as gr # Initialize an empty list to store the tasks tasks = [] def add_task(task): """Add a new task to the list.""" if task.strip(): # Ensure the task is not just whitespace tasks.append(task.strip()) return tasks def get_tasks(): """Return the current list of tasks.""" return "\n".join(tasks) def clear_tasks(): """Clear all tasks from the list.""" tasks.clear() return "" # Define the Gradio interface with gr.Blocks() as demo: gr.Markdown("# Simple Todo List") with gr.Row(): task_input = gr.Textbox(label="Enter a new task") add_button = gr.Button("Add Task") task_list = gr.Textbox(label="Your Tasks", lines=10, interactive=False) with gr.Row(): clear_button = gr.Button("Clear All Tasks") # Event handlers add_button.click(fn=add_task, inputs=task_input, outputs=task_list) task_input.submit(fn=add_task, inputs=task_input, outputs=task_list) clear_button.click(fn=clear_tasks, outputs=[task_list, task_input]) # Launch the app demo.launch()