File size: 1,736 Bytes
a7466b5
096f93d
 
0c6d9d1
 
096f93d
 
 
 
0c6d9d1
 
 
 
 
 
 
 
 
 
096f93d
 
0c6d9d1
 
 
 
 
096f93d
0c6d9d1
096f93d
 
 
 
0c6d9d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import firebase_admin
from firebase_admin import credentials, firestore
from datetime import datetime

# Initialize Firebase
cred = credentials.Certificate("firebase-key.json")
firebase_admin.initialize_app(cred)
db = firestore.client()

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()
        # Add to Firebase
        db.collection("tasks").add({
            "task": task,
            "created": current_time,
            "status": "pending"
        })
        response = f"βœ… Task added: {task}\nCreated at: {current_time}"
    
    elif message == "/list":
        # Get from Firebase
        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

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