import gradio as gr import time from datetime import datetime tasks = [] def add_task(message, history): if not message: return "", history history = history or [] current_time = datetime.now().strftime("%Y-%m-%d %H:%M") if message.startswith("/task"): task = message[6:].strip() tasks.append({ "task": task, "created": current_time, "status": "pending" }) response = f"✅ Task added: {task}\nCreated at: {current_time}" elif message == "/list": if not tasks: response = "No tasks found." else: response = "📋 Tasks:\n" + "\n".join([ f"{i+1}. {task['task']} ({task['status']}) - {task['created']}" for i, task in enumerate(tasks) ]) else: response = "Commands:\n/task [description] - Add new task\n/list - View all tasks" history.append((message, response)) return "", history with gr.Blocks() as demo: gr.Markdown("# 📝 TaskMate") gr.Markdown("### Task Management Made Simple") chatbot = gr.Chatbot(height=400) msg = gr.Textbox( placeholder="Type /task [description] to add a task, or /list to view tasks", label="Input" ) msg.submit(add_task, [msg, chatbot], [msg, chatbot]) demo.launch()