File size: 2,236 Bytes
c9e7c73
a7466b5
096f93d
 
0c6d9d1
c9e7c73
 
0c6d9d1
c9e7c73
 
 
 
 
 
 
 
 
 
 
0c6d9d1
 
c9e7c73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c6d9d1
 
c9e7c73
 
 
 
 
 
 
 
 
 
0c6d9d1
c9e7c73
 
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
import os
import gradio as gr
import firebase_admin
from firebase_admin import credentials, firestore
from datetime import datetime
from dotenv import load_dotenv
from pathlib import Path

load_dotenv()

BASE_DIR = Path(__file__).resolve().parent
FIREBASE_KEY = BASE_DIR / 'firebase-key.json'

try:
   cred = credentials.Certificate(str(FIREBASE_KEY))
   firebase_admin.initialize_app(cred)
   db = firestore.client()
except Exception as e:
   print(f"Firebase initialization error: {e}")

def add_task(message, history):
   try:
       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()
           if not task:
               return "", history + [("", "Task description required")]
           
           db.collection("tasks").add({
               "task": task,
               "created": current_time,
               "status": "pending"
           })
           response = f"βœ… Task added: {task}\nCreated at: {current_time}"
           
       elif message == "/list":
           tasks_ref = db.collection("tasks").stream()
           tasks = [task.to_dict() for task in tasks_ref]
           
           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
       
   except Exception as e:
       return "", history + [("", f"Error: {str(e)}")]

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])

if __name__ == "__main__":
   demo.launch()