Spaces:
Sleeping
Sleeping
Download app.py from Student3331/to_do_list: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/Student3331/to_do_list/resolve/main/app.py
- Command line
-
hf download hf://spaces/Student3331/to_do_list/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Student3331/to_do_list/resolve/main/app.py
1.23 kB
| import streamlit as st | |
| # To store tasks | |
| if "tasks" not in st.session_state: | |
| st.session_state["tasks"] = [] | |
| # Function to add task | |
| def add_task(): | |
| task = st.text_input("Enter a task", key="task_input") | |
| if task: | |
| st.session_state["tasks"].append({"task": task, "done": False}) | |
| # Function to mark task as done | |
| def mark_done(index): | |
| st.session_state["tasks"][index]["done"] = True | |
| # Function to delete task | |
| def delete_task(index): | |
| del st.session_state["tasks"][index] | |
| # UI layout | |
| st.title("To-Do List") | |
| add_task() | |
| # Display tasks | |
| if st.session_state["tasks"]: | |
| for idx, task in enumerate(st.session_state["tasks"]): | |
| task_status = "✔️ Done" if task["done"] else "❌ Pending" | |
| col1, col2, col3 = st.columns([4, 1, 1]) | |
| col1.write(task["task"] + " - " + task_status) | |
| if not task["done"]: | |
| with col2: | |
| if st.button("Mark as Done", key=f"done_{idx}"): | |
| mark_done(idx) | |
| st.experimental_rerun() | |
| with col3: | |
| if st.button("Delete", key=f"delete_{idx}"): | |
| delete_task(idx) | |
| st.experimental_rerun() | |
| else: | |
| st.write("No tasks yet. Add some!") | |