Spaces:
Sleeping
Sleeping
File size: 1,086 Bytes
44a53fd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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() |