Spaces:
Runtime error
Runtime error
File size: 32,085 Bytes
b5e8db1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
"""
Schedule & Note Management Web App
A lightweight Gradio 6 application for managing tasks, events, reminders, and fees.
Based on Product Requirements Document v1.0
"""
import gradio as gr
import json
from datetime import datetime, timedelta
from typing import Optional
from enum import Enum
# ============================================================================
# DATA MODELS AND STATE MANAGEMENT
# ============================================================================
class TaskPriority(str, Enum):
LOW = "Low"
MEDIUM = "Medium"
HIGH = "High"
class TaskStatus(str, Enum):
PENDING = "Pending"
COMPLETED = "Completed"
class ReminderType(str, Enum):
NONE = "None"
BEFORE_15_MIN = "15 minutes before"
BEFORE_30_MIN = "30 minutes before"
BEFORE_1_HOUR = "1 hour before"
BEFORE_1_DAY = "1 day before"
# Sample data for demonstration
SAMPLE_TASKS = [
{
"id": "1",
"title": "Team Meeting",
"description": "Weekly sync with the development team",
"date": datetime.now().strftime("%Y-%m-%d"),
"time": "09:00",
"priority": TaskPriority.HIGH.value,
"status": TaskStatus.PENDING.value,
"fee": 0.0,
"reminder": ReminderType.BEFORE_15_MIN.value,
"notes": "Prepare agenda beforehand",
"created_at": datetime.now().isoformat()
},
{
"id": "2",
"title": "Client Presentation",
"description": "Present the new product roadmap",
"date": datetime.now().strftime("%Y-%m-%d"),
"time": "14:00",
"priority": TaskPriority.HIGH.value,
"status": TaskStatus.PENDING.value,
"fee": 150.0,
"reminder": ReminderType.BEFORE_1_HOUR.value,
"notes": "Review slides and prepare demo",
"created_at": datetime.now().isoformat()
},
{
"id": "3",
"title": "Code Review",
"description": "Review PRs for the new feature branch",
"date": (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d"),
"time": "11:00",
"priority": TaskPriority.MEDIUM.value,
"status": TaskStatus.PENDING.value,
"fee": 0.0,
"reminder": ReminderType.BEFORE_30_MIN.value,
"notes": "Check for security vulnerabilities",
"created_at": datetime.now().isoformat()
},
{
"id": "4",
"title": "Gym Session",
"description": "Weekly workout routine",
"date": datetime.now().strftime("%Y-%m-%d"),
"time": "18:00",
"priority": TaskPriority.LOW.value,
"status": TaskStatus.COMPLETED.value,
"fee": 50.0,
"reminder": ReminderType.NONE.value,
"notes": "Focus on cardio today",
"created_at": datetime.now().isoformat()
}
]
def get_next_id(tasks: list) -> str:
"""Generate a new unique ID for tasks."""
if not tasks:
return "1"
max_id = max(int(task["id"]) for task in tasks)
return str(max_id + 1)
def calculate_weekly_stats(tasks: list) -> dict:
"""Calculate statistics for the current week."""
now = datetime.now()
week_start = now - timedelta(days=now.weekday())
week_end = week_start + timedelta(days=6)
weekly_tasks = [
t for t in tasks
if week_start.strftime("%Y-%m-%d") <= t["date"] <= week_end.strftime("%Y-%m-%d")
]
completed = sum(1 for t in weekly_tasks if t["status"] == TaskStatus.COMPLETED.value)
total_fee = sum(float(t.get("fee", 0) or 0) for t in weekly_tasks)
return {
"total_tasks": len(weekly_tasks),
"completed": completed,
"pending": len(weekly_tasks) - completed,
"total_fee": total_fee,
"completion_rate": round((completed / len(weekly_tasks) * 100), 1) if weekly_tasks else 0
}
def get_weekly_schedule(tasks: list) -> str:
"""Generate a weekly schedule display."""
now = datetime.now()
days = []
for i in range(7):
day = now + timedelta(days=i)
day_str = day.strftime("%Y-%m-%d")
day_name = day.strftime("%A")
is_today = i == 0
day_tasks = [
f" β’ **{t['time']}** - {t['title']}"
for t in sorted(tasks, key=lambda x: x.get("time", ""))
if t["date"] == day_str
]
day_header = f"**{day_name} {day.strftime('%b %d')}" + (' (Today)' if is_today else '') + "**"
day_content = "\n".join(day_tasks) if day_tasks else " No tasks scheduled"
days.append(f"{day_header}\n{day_content}")
return "\n\n".join(days)
# ============================================================================
# APPLICATION STATE
# ============================================================================
class AppState:
"""Application state manager for Gradio 6."""
def __init__(self):
self.tasks = SAMPLE_TASKS.copy()
def get_tasks(self) -> list:
"""Get all tasks."""
return self.tasks
def add_task(self, task: dict) -> None:
"""Add a new task."""
task["id"] = get_next_id(self.tasks)
task["created_at"] = datetime.now().isoformat()
self.tasks.append(task)
def update_task(self, task_id: str, updates: dict) -> None:
"""Update an existing task."""
for task in self.tasks:
if task["id"] == task_id:
task.update(updates)
break
def delete_task(self, task_id: str) -> None:
"""Delete a task by ID."""
self.tasks = [t for t in self.tasks if t["id"] != task_id]
def get_task_by_id(self, task_id: str) -> Optional[dict]:
"""Get a task by its ID."""
for task in self.tasks:
if task["id"] == task_id:
return task
return None
# Initialize global state
app_state = AppState()
# ============================================================================
# HELPER FUNCTIONS
# ============================================================================
def refresh_task_list() -> dict:
"""Refresh the task list and return current state."""
tasks = app_state.get_tasks()
return {
task_list: create_task_cards(tasks),
task_count: f"Total Tasks: {len(tasks)}",
weekly_stats: create_weekly_stats_display(),
weekly_schedule: get_weekly_schedule(tasks)
}
def create_task_cards(tasks: list) -> str:
"""Create HTML cards for task display."""
if not tasks:
return """
<div style="text-align: center; padding: 40px; color: #666;">
<h3>π No tasks yet</h3>
<p>Create your first task to get started!</p>
</div>
"""
cards = []
sorted_tasks = sorted(tasks, key=lambda x: (x.get("date", ""), x.get("time", "")))
for task in sorted_tasks:
priority_colors = {
"Low": "#28a745",
"Medium": "#ffc107",
"High": "#dc3545"
}
status_colors = {
"Pending": "#6c757d",
"Completed": "#28a745"
}
priority_color = priority_colors.get(task.get("priority", "Medium"), "#6c757d")
status_color = status_colors.get(task.get("status", "Pending"), "#6c757d")
card = f"""
<div style="
background: white;
border-radius: 12px;
padding: 16px;
margin-bottom: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
border-left: 4px solid {priority_color};
">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px;">
<div>
<h4 style="margin: 0; color: #333;">{task['title']}</h4>
<span style="
display: inline-block;
background: {priority_color}20;
color: {priority_color};
padding: 2px 8px;
border-radius: 4px;
font-size: 12px;
margin-top: 4px;
">{task.get('priority', 'Medium')}</span>
<span style="
display: inline-block;
background: {status_color}20;
color: {status_color};
padding: 2px 8px;
border-radius: 4px;
font-size: 12px;
margin-left: 8px;
">{task.get('status', 'Pending')}</span>
</div>
<div style="text-align: right; color: #666; font-size: 14px;">
<div>π
{task.get('date', 'No date')}</div>
<div>π {task.get('time', 'No time')}</div>
</div>
</div>
<p style="color: #666; font-size: 14px; margin: 8px 0;">
{task.get('description', 'No description')}
</p>
<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid #eee;">
<div style="font-size: 14px;">
{'π° Fee: $' + str(task.get('fee', 0)) if float(task.get('fee', 0)) > 0 else ''}
{' | β° Reminder: ' + task.get('reminder', 'None') if task.get('reminder') != 'None' else ''}
</div>
<div style="display: flex; gap: 8px;">
<span style="font-size: 12px; color: #666;">ID: {task['id']}</span>
</div>
</div>
</div>
"""
cards.append(card)
return "\n".join(cards)
def create_weekly_stats_display() -> str:
"""Create weekly statistics display."""
stats = calculate_weekly_stats(app_state.get_tasks())
return f"""
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px;">
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; border-radius: 12px; text-align: center;">
<div style="font-size: 32px; font-weight: bold;">{stats['total_tasks']}</div>
<div style="font-size: 14px; opacity: 0.9;">This Week's Tasks</div>
</div>
<div style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: white; padding: 20px; border-radius: 12px; text-align: center;">
<div style="font-size: 32px; font-weight: bold;">{stats['completed']}</div>
<div style="font-size: 14px; opacity: 0.9;">Completed</div>
</div>
<div style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: white; padding: 20px; border-radius: 12px; text-align: center;">
<div style="font-size: 32px; font-weight: bold;">{stats['pending']}</div>
<div style="font-size: 14px; opacity: 0.9;">Pending</div>
</div>
<div style="background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); color: white; padding: 20px; border-radius: 12px; text-align: center;">
<div style="font-size: 32px; font-weight: bold;">${stats['total_fee']:.2f}</div>
<div style="font-size: 14px; opacity: 0.9;">Total Fees</div>
</div>
</div>
"""
# ============================================================================
# TASK OPERATIONS
# ============================================================================
def add_new_task(
title: str,
description: str,
task_date: str,
task_time: str,
priority: str,
fee: float,
reminder: str,
notes: str
) -> dict:
"""Add a new task to the system."""
if not title or not task_date or not task_time:
return {
task_list: create_task_cards(app_state.get_tasks()),
status_msg: gr.update(value="β Please fill in all required fields!", visible=True),
form_message: gr.update(value="β Error: Title, date, and time are required", visible=True)
}
new_task = {
"title": title,
"description": description,
"date": task_date,
"time": task_time,
"priority": priority,
"status": TaskStatus.PENDING.value,
"fee": fee,
"reminder": reminder,
"notes": notes
}
app_state.add_task(new_task)
return {
task_list: create_task_cards(app_state.get_tasks()),
status_msg: gr.update(value="β
Task created successfully!", visible=True),
form_message: gr.update(value="β
Task added successfully!", visible=True),
# Clear form
title_input: gr.update(value=""),
description_input: gr.update(value=""),
fee_input: gr.update(value=0.0),
notes_input: gr.update(value="")
}
def update_task_status(task_id: str, new_status: str) -> dict:
"""Update a task's status."""
if task_id and new_status:
app_state.update_task(task_id, {"status": new_status})
return {
task_list: create_task_cards(app_state.get_tasks()),
status_msg: gr.update(value=f"β
Task {task_id} marked as {new_status}", visible=True)
}
def delete_task_action(task_id: str) -> dict:
"""Delete a task."""
if task_id:
app_state.delete_task(task_id)
return {
task_list: create_task_cards(app_state.get_tasks()),
status_msg: gr.update(value=f"β
Task deleted successfully", visible=True)
}
def load_task_for_edit(task_id: str) -> dict:
"""Load task data into the edit form."""
task = app_state.get_task_by_id(task_id)
if task:
return {
edit_task_id: task_id,
edit_title: gr.update(value=task["title"]),
edit_description: gr.update(value=task.get("description", "")),
edit_date: gr.update(value=task.get("date", "")),
edit_time: gr.update(value=task.get("time", "")),
edit_priority: gr.update(value=task.get("priority", "Medium")),
edit_fee: gr.update(value=float(task.get("fee", 0) or 0)),
edit_reminder: gr.update(value=task.get("reminder", "None")),
edit_notes: gr.update(value=task.get("notes", "")),
show_edit_form: gr.update(visible=True)
}
return {show_edit_form: gr.update(visible=False)}
def save_edited_task(
task_id: str,
title: str,
description: str,
task_date: str,
task_time: str,
priority: str,
fee: float,
reminder: str,
notes: str
) -> dict:
"""Save edited task."""
if task_id and title:
updates = {
"title": title,
"description": description,
"date": task_date,
"time": task_time,
"priority": priority,
"fee": fee,
"reminder": reminder,
"notes": notes
}
app_state.update_task(task_id, updates)
return {
task_list: create_task_cards(app_state.get_tasks()),
status_msg: gr.update(value="β
Task updated successfully!", visible=True),
show_edit_form: gr.update(visible=False)
}
def filter_tasks(status_filter: str, priority_filter: str) -> dict:
"""Filter tasks by status and priority."""
tasks = app_state.get_tasks()
if status_filter != "All":
tasks = [t for t in tasks if t.get("status") == status_filter]
if priority_filter != "All":
tasks = [t for t in tasks if t.get("priority") == priority_filter]
return {
task_list: create_task_cards(tasks)
}
def search_tasks(search_query: str) -> dict:
"""Search tasks by title or description."""
if not search_query.strip():
return {task_list: create_task_cards(app_state.get_tasks())}
query = search_query.lower()
tasks = [
t for t in app_state.get_tasks()
if query in t.get("title", "").lower() or query in t.get("description", "").lower()
]
return {
task_list: create_task_cards(tasks)
}
# ============================================================================
# GRADIO 6 APPLICATION
# ============================================================================
# Custom theme for the application
custom_theme = gr.themes.Soft(
primary_hue="indigo",
secondary_hue="purple",
neutral_hue="slate",
font=gr.themes.GoogleFont("Inter"),
text_size="lg",
spacing_size="lg",
radius_size="md"
).set(
button_primary_background_fill="*primary_600",
button_primary_background_fill_hover="*primary_700",
button_secondary_background_fill="*secondary_100",
button_secondary_background_fill_hover="*secondary_200",
block_title_text_weight="600",
block_background_fill="white",
block_radius="12px",
)
with gr.Blocks(theme=custom_theme) as demo:
# Header
gr.HTML("""
<div style="text-align: center; padding: 20px 0; margin-bottom: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px; color: white;">
<h1 style="margin: 0; font-size: 28px;">π
Schedule & Note Management</h1>
<p style="margin: 8px 0 0 0; opacity: 0.9;">Plan tasks, manage events, and track fees efficiently</p>
</div>
""")
gr.HTML("""
<div style="text-align: right; margin-bottom: 10px;">
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #667eea; text-decoration: none; font-size: 14px;">
β¨ Built with anycoder
</a>
</div>
""")
# Main content with tabs
with gr.Tabs() as tabs:
# Tab 1: Dashboard
with gr.TabItem("π Dashboard", id="dashboard"):
gr.Markdown("### π Weekly Overview")
with gr.Row():
with gr.Column(scale=2):
weekly_stats_html = gr.HTML(
value=create_weekly_stats_display(),
elem_id="weekly-stats"
)
with gr.Column(scale=1):
gr.Markdown("### π
Quick Stats")
task_count = gr.Markdown(f"**Total Tasks: {len(app_state.get_tasks())}**")
gr.Markdown("### π This Week's Schedule")
weekly_schedule = gr.Markdown(
value=get_weekly_schedule(app_state.get_tasks()),
elem_id="weekly-schedule"
)
status_msg = gr.Markdown(visible=False, value="")
# Tab 2: Task Management
with gr.TabItem("β
Tasks", id="tasks"):
gr.Markdown("### β
Task Management")
# Search and filter row
with gr.Row():
with gr.Column(scale=3):
search_input = gr.Textbox(
label="π Search Tasks",
placeholder="Search by title or description...",
elem_id="search-input"
)
with gr.Column(scale=1):
status_filter = gr.Dropdown(
choices=["All", "Pending", "Completed"],
value="All",
label="Status"
)
with gr.Column(scale=1):
priority_filter = gr.Dropdown(
choices=["All", "Low", "Medium", "High"],
value="All",
label="Priority"
)
# Task list display
task_list = gr.HTML(
value=create_task_cards(app_state.get_tasks()),
elem_id="task-list"
)
status_msg = gr.Markdown(visible=False, value="")
# Tab 3: Add New Task
with gr.TabItem("β Add Task", id="add-task"):
gr.Markdown("### β Create New Task")
with gr.Row():
with gr.Column(scale=2):
title_input = gr.Textbox(
label="Task Title *",
placeholder="Enter task title",
elem_id="title-input"
)
description_input = gr.Textbox(
label="Description",
placeholder="Enter task description",
lines=3,
elem_id="description-input"
)
with gr.Column(scale=1):
task_date = gr.DateTime(
label="Date & Time *",
type="datetime",
elem_id="task-date"
)
task_time = gr.Textbox(
label="Time (HH:MM) *",
placeholder="09:00",
value="09:00",
elem_id="task-time"
)
with gr.Row():
with gr.Column():
priority = gr.Radio(
choices=["Low", "Medium", "High"],
value="Medium",
label="Priority"
)
with gr.Column():
fee_input = gr.Number(
label="Fee/Cost ($)",
value=0.0,
minimum=0.0,
elem_id="fee-input"
)
with gr.Column():
reminder = gr.Dropdown(
choices=["None", "15 minutes before", "30 minutes before",
"1 hour before", "1 day before"],
value="None",
label="Reminder"
)
notes_input = gr.Textbox(
label="Notes",
placeholder="Additional notes or comments...",
lines=2,
elem_id="notes-input"
)
form_message = gr.Markdown(visible=False, value="")
with gr.Row():
add_btn = gr.Button("Create Task", variant="primary", size="lg")
clear_btn = gr.Button("Clear Form", variant="secondary")
# Tab 4: Edit Task
with gr.TabItem("βοΈ Edit Task", id="edit-task"):
gr.Markdown("### βοΈ Edit Task")
# Task selection dropdown
task_selector = gr.Dropdown(
choices=[(f"{t['title']} ({t.get('date', 'No date')}) - ID:{t['id']}", t['id'])
for t in app_state.get_tasks()],
label="Select Task to Edit",
allow_custom_value=True,
elem_id="task-selector"
)
show_edit_form = gr.Column(visible=False, elem_id="edit-form-container")
with show_edit_form:
edit_task_id = gr.Textbox(visible=False, elem_id="edit-task-id")
with gr.Row():
with gr.Column(scale=2):
edit_title = gr.Textbox(
label="Task Title *",
placeholder="Enter task title",
elem_id="edit-title"
)
edit_description = gr.Textbox(
label="Description",
placeholder="Enter task description",
lines=3,
elem_id="edit-description"
)
with gr.Column(scale=1):
edit_date = gr.Textbox(
label="Date (YYYY-MM-DD) *",
placeholder="2024-01-15",
elem_id="edit-date"
)
edit_time = gr.Textbox(
label="Time (HH:MM) *",
placeholder="09:00",
elem_id="edit-time"
)
with gr.Row():
with gr.Column():
edit_priority = gr.Radio(
choices=["Low", "Medium", "High"],
value="Medium",
label="Priority"
)
with gr.Column():
edit_fee = gr.Number(
label="Fee/Cost ($)",
value=0.0,
minimum=0.0,
elem_id="edit-fee"
)
with gr.Column():
edit_reminder = gr.Dropdown(
choices=["None", "15 minutes before", "30 minutes before",
"1 hour before", "1 day before"],
value="None",
label="Reminder"
)
edit_notes = gr.Textbox(
label="Notes",
placeholder="Additional notes or comments...",
lines=2,
elem_id="edit-notes"
)
with gr.Row():
save_btn = gr.Button("Save Changes", variant="primary", size="lg")
cancel_btn = gr.Button("Cancel", variant="secondary")
# Tab 5: Notes Manager
with gr.TabItem("π Notes", id="notes"):
gr.Markdown("### π Quick Notes")
gr.Markdown("*Notes are attached to individual tasks. View task notes in the Tasks tab.*")
with gr.Row():
quick_note = gr.Textbox(
label="Quick Note",
placeholder="Write a quick note...",
lines=4
)
note_display = gr.Markdown(
value="**Recent Notes**\n\nβ’ Review meeting notes from Monday\nβ’ Update project timeline\nβ’ Prepare budget report",
elem_id="note-display"
)
with gr.Row():
save_note_btn = gr.Button("Save Note", variant="primary")
clear_note_btn = gr.Button("Clear", variant="secondary")
# Tab 6: Fees Summary
with gr.TabItem("π° Fees", id="fees"):
gr.Markdown("### π° Fee Tracking Summary")
# Fee statistics
tasks = app_state.get_tasks()
total_fees = sum(float(t.get("fee", 0) or 0) for t in tasks)
task_with_fees = sum(1 for t in tasks if float(t.get("fee", 0) or 0) > 0)
avg_fee = total_fees / task_with_fees if task_with_fees > 0 else 0
gr.HTML(f"""
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px;">
<div style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: white; padding: 24px; border-radius: 12px; text-align: center;">
<div style="font-size: 36px; font-weight: bold;">${total_fees:.2f}</div>
<div style="font-size: 16px; opacity: 0.9;">Total Fees</div>
</div>
<div style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: white; padding: 24px; border-radius: 12px; text-align: center;">
<div style="font-size: 36px; font-weight: bold;">{task_with_fees}</div>
<div style="font-size: 16px; opacity: 0.9;">Tasks with Fees</div>
</div>
<div style="background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); color: white; padding: 24px; border-radius: 12px; text-align: center;">
<div style="font-size: 36px; font-weight: bold;">${avg_fee:.2f}</div>
<div style="font-size: 16px; opacity: 0.9;">Average Fee</div>
</div>
</div>
""")
gr.Markdown("### π΅ Tasks with Fees")
fee_task_list = gr.HTML(
value=create_task_cards([t for t in tasks if float(t.get("fee", 0) or 0) > 0]),
elem_id="fee-task-list"
)
# ============================================================================
# EVENT HANDLERS
# ============================================================================
# Search and filter handlers
search_input.submit(search_tasks, inputs=search_input, outputs=[task_list])
status_filter.change(filter_tasks, inputs=[status_filter, priority_filter], outputs=[task_list])
priority_filter.change(filter_tasks, inputs=[status_filter, priority_filter], outputs=[task_list])
# Add task handlers
add_btn.click(
add_new_task,
inputs=[title_input, description_input, task_date, task_time,
priority, fee_input, reminder, notes_input],
outputs=[task_list, status_msg, form_message, title_input,
description_input, fee_input, notes_input]
)
clear_btn.click(
lambda: {
title_input: gr.update(value=""),
description_input: gr.update(value=""),
fee_input: gr.update(value=0.0),
notes_input: gr.update(value=""),
form_message: gr.update(visible=False)
},
outputs=[title_input, description_input, fee_input, notes_input, form_message]
)
# Task selector for editing
task_selector.select(
load_task_for_edit,
inputs=task_selector,
outputs=[edit_task_id, edit_title, edit_description, edit_date, edit_time,
edit_priority, edit_fee, edit_reminder, edit_notes, show_edit_form]
)
# Save edited task
save_btn.click(
save_edited_task,
inputs=[edit_task_id, edit_title, edit_description, edit_date, edit_time,
edit_priority, edit_fee, edit_reminder, edit_notes],
outputs=[task_list, status_msg, show_edit_form]
)
# Cancel edit
cancel_btn.click(
lambda: {show_edit_form: gr.update(visible=False)},
outputs=[show_edit_form]
)
# Notes handlers
save_note_btn.click(
lambda note: {
note_display: note_display.value + f"\nβ’ {note}" if note else note_display.value
},
inputs=quick_note,
outputs=[note_display]
)
clear_note_btn.click(
lambda: {quick_note: gr.update(value="")},
outputs=[quick_note]
)
# Refresh button (hidden, used for updates)
refresh_btn = gr.Button("Refresh", visible=False)
refresh_btn.click(refresh_task_list, outputs=[task_list, task_count, weekly_stats_html, weekly_schedule])
# ============================================================================
# LAUNCH APPLICATION
# ============================================================================
demo.launch(
theme=gr.themes.Soft(
primary_hue="indigo",
secondary_hue="purple",
neutral_hue="slate",
font=gr.themes.GoogleFont("Inter"),
text_size="lg",
spacing_size="lg",
radius_size="md"
),
title="Schedule & Note Management App",
description="A lightweight application for managing tasks, events, reminders, and fees. Based on PRD v1.0",
css="""
.gradio-container {
max-width: 1200px !important;
}
#weekly-stats, #fee-task-list {
margin-bottom: 20px;
}
#search-input {
border-radius: 8px;
}
""",
footer_links=[
{"label": "Documentation", "url": "#"},
{"label": "Support", "url": "#"},
{"api": "api"}
]
) |