co42 HF staff commited on
Commit
44a53fd
1 Parent(s): b27f7ca

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Initialize an empty list to store the tasks
4
+ tasks = []
5
+
6
+ def add_task(task):
7
+ """Add a new task to the list."""
8
+ if task.strip(): # Ensure the task is not just whitespace
9
+ tasks.append(task.strip())
10
+ return tasks
11
+
12
+ def get_tasks():
13
+ """Return the current list of tasks."""
14
+ return "\n".join(tasks)
15
+
16
+ def clear_tasks():
17
+ """Clear all tasks from the list."""
18
+ tasks.clear()
19
+ return ""
20
+
21
+ # Define the Gradio interface
22
+ with gr.Blocks() as demo:
23
+ gr.Markdown("# Simple Todo List")
24
+
25
+ with gr.Row():
26
+ task_input = gr.Textbox(label="Enter a new task")
27
+ add_button = gr.Button("Add Task")
28
+
29
+ task_list = gr.Textbox(label="Your Tasks", lines=10, interactive=False)
30
+
31
+ with gr.Row():
32
+ clear_button = gr.Button("Clear All Tasks")
33
+
34
+ # Event handlers
35
+ add_button.click(fn=add_task, inputs=task_input, outputs=task_list)
36
+ task_input.submit(fn=add_task, inputs=task_input, outputs=task_list)
37
+ clear_button.click(fn=clear_tasks, outputs=[task_list, task_input])
38
+
39
+ # Launch the app
40
+ demo.launch()