Spaces:
Runtime error
Runtime error
Commit ·
de3f3b9
1
Parent(s): 7baa640
new
Browse files
app.py
CHANGED
|
@@ -3,15 +3,14 @@ import pandas as pd
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
# Initialize an empty to-do list DataFrame
|
| 6 |
-
TODO_COLUMNS = ["Task", "Priority", "Status", "Date"]
|
| 7 |
todo_df = pd.DataFrame(columns=TODO_COLUMNS)
|
| 8 |
|
| 9 |
# Function to add a new task
|
| 10 |
-
def add_task(task, priority, status):
|
| 11 |
global todo_df
|
| 12 |
if task.strip(): # Ensure task is not empty
|
| 13 |
-
|
| 14 |
-
new_task = pd.DataFrame([[task, priority, status, date]], columns=TODO_COLUMNS)
|
| 15 |
todo_df = pd.concat([todo_df, new_task], ignore_index=True)
|
| 16 |
todo_df = sort_tasks(todo_df)
|
| 17 |
return todo_df
|
|
@@ -28,14 +27,15 @@ def delete_task(index):
|
|
| 28 |
def get_tasks():
|
| 29 |
return sort_tasks(todo_df)
|
| 30 |
|
| 31 |
-
# Function to sort tasks by priority (High > Medium > Low)
|
| 32 |
def sort_tasks(df):
|
| 33 |
priority_order = {"High": 0, "Medium": 1, "Low": 2}
|
| 34 |
df["Priority Rank"] = df["Priority"].map(priority_order)
|
| 35 |
-
df =
|
|
|
|
| 36 |
return df
|
| 37 |
|
| 38 |
-
# Function to style the DataFrame for color coding
|
| 39 |
def style_tasks(df):
|
| 40 |
styled_df = df.style.applymap(
|
| 41 |
lambda x: "background-color: #2E8B57;" if x == "Completed" else "",
|
|
@@ -48,7 +48,7 @@ with gr.Blocks() as demo:
|
|
| 48 |
gr.Markdown(
|
| 49 |
"""
|
| 50 |
<div style="text-align: center; font-size: 28px; font-weight: bold; color: #FFA500;">
|
| 51 |
-
📝
|
| 52 |
</div>
|
| 53 |
"""
|
| 54 |
)
|
|
@@ -80,11 +80,16 @@ with gr.Blocks() as demo:
|
|
| 80 |
value="Not Started",
|
| 81 |
elem_id="dropdown"
|
| 82 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
add_button = gr.Button("Add Task", elem_id="button")
|
| 84 |
|
| 85 |
add_button.click(
|
| 86 |
fn=add_task,
|
| 87 |
-
inputs=[task_input, priority_input, status_input],
|
| 88 |
outputs=task_table
|
| 89 |
)
|
| 90 |
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
# Initialize an empty to-do list DataFrame
|
| 6 |
+
TODO_COLUMNS = ["Task", "Priority", "Status", "Due Date"]
|
| 7 |
todo_df = pd.DataFrame(columns=TODO_COLUMNS)
|
| 8 |
|
| 9 |
# Function to add a new task
|
| 10 |
+
def add_task(task, priority, status, due_date):
|
| 11 |
global todo_df
|
| 12 |
if task.strip(): # Ensure task is not empty
|
| 13 |
+
new_task = pd.DataFrame([[task, priority, status, due_date]], columns=TODO_COLUMNS)
|
|
|
|
| 14 |
todo_df = pd.concat([todo_df, new_task], ignore_index=True)
|
| 15 |
todo_df = sort_tasks(todo_df)
|
| 16 |
return todo_df
|
|
|
|
| 27 |
def get_tasks():
|
| 28 |
return sort_tasks(todo_df)
|
| 29 |
|
| 30 |
+
# Function to sort tasks by priority (High > Medium > Low) and by due date
|
| 31 |
def sort_tasks(df):
|
| 32 |
priority_order = {"High": 0, "Medium": 1, "Low": 2}
|
| 33 |
df["Priority Rank"] = df["Priority"].map(priority_order)
|
| 34 |
+
df["Due Date"] = pd.to_datetime(df["Due Date"], errors="coerce") # Convert due date to datetime
|
| 35 |
+
df = df.sort_values(by=["Priority Rank", "Due Date"]).drop(columns=["Priority Rank"]).reset_index(drop=True)
|
| 36 |
return df
|
| 37 |
|
| 38 |
+
# Function to style the DataFrame for color coding completed tasks
|
| 39 |
def style_tasks(df):
|
| 40 |
styled_df = df.style.applymap(
|
| 41 |
lambda x: "background-color: #2E8B57;" if x == "Completed" else "",
|
|
|
|
| 48 |
gr.Markdown(
|
| 49 |
"""
|
| 50 |
<div style="text-align: center; font-size: 28px; font-weight: bold; color: #FFA500;">
|
| 51 |
+
📝 Futuristic To-Do List Tracker
|
| 52 |
</div>
|
| 53 |
"""
|
| 54 |
)
|
|
|
|
| 80 |
value="Not Started",
|
| 81 |
elem_id="dropdown"
|
| 82 |
)
|
| 83 |
+
due_date_input = gr.Textbox(
|
| 84 |
+
label="Due Date (YYYY-MM-DD)",
|
| 85 |
+
placeholder="Enter due date...",
|
| 86 |
+
elem_id="input-box"
|
| 87 |
+
)
|
| 88 |
add_button = gr.Button("Add Task", elem_id="button")
|
| 89 |
|
| 90 |
add_button.click(
|
| 91 |
fn=add_task,
|
| 92 |
+
inputs=[task_input, priority_input, status_input, due_date_input],
|
| 93 |
outputs=task_table
|
| 94 |
)
|
| 95 |
|