Spaces:
Runtime error
Runtime error
Commit ·
2db1b43
1
Parent(s): 2bcb9a1
new
Browse files
app.py
CHANGED
|
@@ -9,7 +9,13 @@ todo_df = pd.DataFrame(columns=TODO_COLUMNS)
|
|
| 9 |
# Function to add a new task
|
| 10 |
def add_task(task, priority, status, due_date):
|
| 11 |
global todo_df
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
|
@@ -27,22 +33,14 @@ def delete_task(index):
|
|
| 27 |
def get_tasks():
|
| 28 |
return sort_tasks(todo_df)
|
| 29 |
|
| 30 |
-
# Function to sort tasks by priority
|
| 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")
|
| 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 "",
|
| 42 |
-
subset=["Status"]
|
| 43 |
-
)
|
| 44 |
-
return styled_df
|
| 45 |
-
|
| 46 |
# Initialize Gradio app with dark tech-inspired theme
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.Markdown(
|
|
@@ -80,9 +78,10 @@ with gr.Blocks() as demo:
|
|
| 80 |
value="Not Started",
|
| 81 |
elem_id="dropdown"
|
| 82 |
)
|
| 83 |
-
due_date_input = gr.
|
| 84 |
-
label="Due Date",
|
| 85 |
-
|
|
|
|
| 86 |
)
|
| 87 |
add_button = gr.Button("Add Task", elem_id="button")
|
| 88 |
|
|
@@ -129,13 +128,6 @@ custom_css = """
|
|
| 129 |
border-radius: 8px;
|
| 130 |
padding: 5px;
|
| 131 |
}
|
| 132 |
-
#date-picker {
|
| 133 |
-
background-color: #1c1c1c;
|
| 134 |
-
color: #E0E0E0;
|
| 135 |
-
border: 1px solid #FFA500;
|
| 136 |
-
border-radius: 8px;
|
| 137 |
-
padding: 10px;
|
| 138 |
-
}
|
| 139 |
#button {
|
| 140 |
background-color: #FFA500;
|
| 141 |
color: #181818;
|
|
|
|
| 9 |
# Function to add a new task
|
| 10 |
def add_task(task, priority, status, due_date):
|
| 11 |
global todo_df
|
| 12 |
+
try:
|
| 13 |
+
# Validate date format
|
| 14 |
+
due_date = datetime.strptime(due_date, "%Y-%m-%d").strftime("%Y-%m-%d")
|
| 15 |
+
except ValueError:
|
| 16 |
+
return todo_df # Skip adding if date is invalid
|
| 17 |
+
|
| 18 |
+
if task.strip():
|
| 19 |
new_task = pd.DataFrame([[task, priority, status, due_date]], columns=TODO_COLUMNS)
|
| 20 |
todo_df = pd.concat([todo_df, new_task], ignore_index=True)
|
| 21 |
todo_df = sort_tasks(todo_df)
|
|
|
|
| 33 |
def get_tasks():
|
| 34 |
return sort_tasks(todo_df)
|
| 35 |
|
| 36 |
+
# Function to sort tasks by priority and due date
|
| 37 |
def sort_tasks(df):
|
| 38 |
priority_order = {"High": 0, "Medium": 1, "Low": 2}
|
| 39 |
df["Priority Rank"] = df["Priority"].map(priority_order)
|
| 40 |
+
df["Due Date"] = pd.to_datetime(df["Due Date"], errors="coerce")
|
| 41 |
df = df.sort_values(by=["Priority Rank", "Due Date"]).drop(columns=["Priority Rank"]).reset_index(drop=True)
|
| 42 |
return df
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# Initialize Gradio app with dark tech-inspired theme
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
gr.Markdown(
|
|
|
|
| 78 |
value="Not Started",
|
| 79 |
elem_id="dropdown"
|
| 80 |
)
|
| 81 |
+
due_date_input = gr.Textbox(
|
| 82 |
+
label="Due Date (YYYY-MM-DD)",
|
| 83 |
+
placeholder="YYYY-MM-DD",
|
| 84 |
+
elem_id="input-box"
|
| 85 |
)
|
| 86 |
add_button = gr.Button("Add Task", elem_id="button")
|
| 87 |
|
|
|
|
| 128 |
border-radius: 8px;
|
| 129 |
padding: 5px;
|
| 130 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
#button {
|
| 132 |
background-color: #FFA500;
|
| 133 |
color: #181818;
|