jvnickerson commited on
Commit
32a246d
·
verified ·
1 Parent(s): f0b0487

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +3 -9
  2. todo.py +64 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Todo.py
3
- emoji: 🐨
4
- colorFrom: pink
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 4.44.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: todo.py
3
+ app_file: todo.py
 
 
4
  sdk: gradio
5
+ sdk_version: 4.39.0
 
 
6
  ---
 
 
todo.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import os
4
+
5
+ # File to store todos
6
+ TODOS_FILE = "todos.json"
7
+
8
+ def load_todos():
9
+ if os.path.exists(TODOS_FILE):
10
+ with open(TODOS_FILE, "r") as f:
11
+ return json.load(f)
12
+ return []
13
+
14
+ def save_todos(todos):
15
+ with open(TODOS_FILE, "w") as f:
16
+ json.dump(todos, f)
17
+
18
+ def add_todo(todo, todos):
19
+ if todo:
20
+ todos.append(todo)
21
+ save_todos(todos)
22
+ return "", todos
23
+
24
+ def move_todo(direction, index, todos):
25
+ if direction == "Up" and index > 0:
26
+ todos[index], todos[index-1] = todos[index-1], todos[index]
27
+ elif direction == "Down" and index < len(todos) - 1:
28
+ todos[index], todos[index+1] = todos[index+1], todos[index]
29
+ save_todos(todos)
30
+ return todos
31
+
32
+ def delete_todo(index, todos):
33
+ if 0 <= index < len(todos):
34
+ del todos[index]
35
+ save_todos(todos)
36
+ return todos
37
+
38
+ with gr.Blocks() as app:
39
+ gr.Markdown("# Todo Priority Manager")
40
+
41
+ todos = gr.State(load_todos())
42
+
43
+ with gr.Row():
44
+ todo_input = gr.Textbox(label="New Todo")
45
+ add_btn = gr.Button("Add Todo")
46
+
47
+ todo_list = gr.Textbox(label="Todos", lines=10, interactive=False)
48
+
49
+ with gr.Row():
50
+ move_up = gr.Button("Move Up")
51
+ move_down = gr.Button("Move Down")
52
+ delete_btn = gr.Button("Delete")
53
+
54
+ add_btn.click(add_todo, inputs=[todo_input, todos], outputs=[todo_input, todo_list])
55
+ move_up.click(
56
+ move_todo,
57
+ inputs=[gr.Textbox(value="Up"), todo_list, todos],
58
+ outputs=[todo_list]
59
+ )cd
60
+ move_down.click(move_todo, inputs=[gr.Textbox(value="Down"), todo_list, todos], outputs=[todo_list])
61
+ delete_btn.click(delete_todo, inputs=[todo_list, todos], outputs=[todo_list])
62
+
63
+ if __name__ == "__main__":
64
+ app.launch(share=True)