Taskmate / app.py
JanviMl's picture
Update app.py
096f93d verified
raw
history blame
1.74 kB
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()