Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
# Application title
|
6 |
+
st.set_page_config(page_title="To-Do Notebook", page_icon="π", layout="centered")
|
7 |
+
|
8 |
+
# App header
|
9 |
+
st.title("π To-Do Notebook")
|
10 |
+
st.subheader("Organize your tasks with ease!")
|
11 |
+
|
12 |
+
# App description
|
13 |
+
st.write("Add your tasks, check them off, and delete them when you're done.")
|
14 |
+
|
15 |
+
# Initialize task list in the session state
|
16 |
+
if "tasks" not in st.session_state:
|
17 |
+
st.session_state.tasks = []
|
18 |
+
|
19 |
+
# Function to add a task
|
20 |
+
def add_task(task_name, priority, deadline):
|
21 |
+
if task_name:
|
22 |
+
st.session_state.tasks.append({
|
23 |
+
"task": task_name,
|
24 |
+
"priority": priority,
|
25 |
+
"deadline": deadline,
|
26 |
+
"completed": False
|
27 |
+
})
|
28 |
+
st.success(f"Task '{task_name}' added!")
|
29 |
+
|
30 |
+
# Function to toggle task completion
|
31 |
+
def toggle_completion(index):
|
32 |
+
st.session_state.tasks[index]["completed"] = not st.session_state.tasks[index]["completed"]
|
33 |
+
|
34 |
+
# Function to delete a task
|
35 |
+
def delete_task(index):
|
36 |
+
st.session_state.tasks.pop(index)
|
37 |
+
st.success("Task deleted!")
|
38 |
+
|
39 |
+
# Add task section
|
40 |
+
with st.expander("β Add a New Task"):
|
41 |
+
task_name = st.text_input("Task Name", placeholder="Enter task here...")
|
42 |
+
priority = st.selectbox("Priority", ["Low", "Medium", "High"])
|
43 |
+
deadline = st.date_input("Deadline")
|
44 |
+
if st.button("Add Task"):
|
45 |
+
add_task(task_name, priority, deadline)
|
46 |
+
|
47 |
+
# Show tasks
|
48 |
+
if st.session_state.tasks:
|
49 |
+
st.subheader("π Your Tasks")
|
50 |
+
for i, task in enumerate(st.session_state.tasks):
|
51 |
+
col1, col2, col3 = st.columns([5, 2, 1])
|
52 |
+
|
53 |
+
# Display task with checkbox
|
54 |
+
with col1:
|
55 |
+
st.checkbox(
|
56 |
+
f"({task['priority']}) {task['task']} - Due: {task['deadline']}",
|
57 |
+
value=task["completed"],
|
58 |
+
on_change=toggle_completion,
|
59 |
+
args=(i,)
|
60 |
+
)
|
61 |
+
# Delete button
|
62 |
+
with col3:
|
63 |
+
if st.button("ποΈ", key=f"delete_{i}"):
|
64 |
+
delete_task(i)
|
65 |
+
else:
|
66 |
+
st.info("You have no tasks. Add a new task to get started!")
|
67 |
+
|
68 |
+
# Footer
|
69 |
+
st.write("---")
|
70 |
+
st.write("β¨ Made with β€οΈ using Streamlit")
|
71 |
+
|
72 |
+
# Run Streamlit locally or deploy
|
73 |
+
!streamlit run app.py
|