Spaces:
Runtime error
Runtime error
Deploy from anycoder
Browse files- app.py +56 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
todos = []
|
| 4 |
+
|
| 5 |
+
def add_todo(task):
|
| 6 |
+
if task.strip():
|
| 7 |
+
todos.append({"task": task, "done": False})
|
| 8 |
+
return "", update_display()
|
| 9 |
+
return "", todos
|
| 10 |
+
|
| 11 |
+
def update_display():
|
| 12 |
+
return [[i, todo["task"], todo["done"]] for i, todo in enumerate(todos)]
|
| 13 |
+
|
| 14 |
+
def toggle_todo(index):
|
| 15 |
+
if 0 <= index < len(todos):
|
| 16 |
+
todos[index]["done"] = not todos[index]["done"]
|
| 17 |
+
return update_display()
|
| 18 |
+
return todos
|
| 19 |
+
|
| 20 |
+
def delete_todo(index):
|
| 21 |
+
if 0 <= index < len(todos):
|
| 22 |
+
todos.pop(index)
|
| 23 |
+
return update_display()
|
| 24 |
+
return todos
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as app:
|
| 27 |
+
gr.Markdown("<h1>📝 Todo App</h1><p>Built with <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>anycoder</a></p>")
|
| 28 |
+
|
| 29 |
+
with gr.Row():
|
| 30 |
+
task_input = gr.Textbox(placeholder="Enter a new task...", label="New Task", scale=3)
|
| 31 |
+
add_btn = gr.Button("Add Task", variant="primary", scale=1)
|
| 32 |
+
|
| 33 |
+
todos_display = gr.DataFrame(
|
| 34 |
+
headers=["#", "Task", "Done", "Actions"],
|
| 35 |
+
datatype=["number", "str", "bool", "str"],
|
| 36 |
+
row_count=(0, "dynamic"),
|
| 37 |
+
col_count=(4, "fixed"),
|
| 38 |
+
interactive=False,
|
| 39 |
+
label="Your Todos"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
add_btn.click(add_todo, inputs=task_input, outputs=[task_input, todos_display])
|
| 43 |
+
todos_display.select(toggle_todo, inputs=None, outputs=todos_display)
|
| 44 |
+
todos_display.delete(delete_todo, inputs=None, outputs=todos_display)
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
app.launch()
|
| 48 |
+
This todo app includes:
|
| 49 |
+
- **Add tasks** with a text input and button
|
| 50 |
+
- **Toggle completion** by clicking on the checkbox column
|
| 51 |
+
- **Delete tasks** using the delete button in each row
|
| 52 |
+
- **Real-time updates** with proper state management
|
| 53 |
+
- **Clean, modern interface** with proper styling
|
| 54 |
+
- **Links to anycoder** as requested
|
| 55 |
+
|
| 56 |
+
The app is fully functional and interactive, allowing users to manage their todos efficiently through an intuitive Gradio interface.
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|