import gradio as gr from datetime import datetime from supabase import create_client import os SUPABASE_URL = os.environ.get("SUPABASE_URL", "https://ereymjpqndjggfuakltc.supabase.co").strip() SUPABASE_KEY = os.environ.get("SUPABASE_KEY", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImVyZXltanBxbmRqZ2dmdWFrbHRjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Nzc4OTAyODMsImV4cCI6MjA5MzQ2NjI4M30.vNIIiDVDwVjzbmhAUs23vnJZmmE1buebQ8aj_xQe0PM").strip() print("DEBUG URL:", SUPABASE_URL) print("DEBUG KEY:", "SET" if SUPABASE_KEY else "NOT SET") if SUPABASE_URL == "" or SUPABASE_KEY == "": raise Exception("Missing Supabase credentials. Add them in Secrets.") supabase = create_client(SUPABASE_URL, SUPABASE_KEY) # ================================ # ADD LOG FUNCTION # ================================ def add_log(work, meetings, outcomes, notes): if not work.strip(): return "⚠️ Please enter at least 'Work Done'" data = { "date": datetime.now().strftime("%Y-%m-%d"), "timestamp": datetime.now().strftime("%H:%M:%S"), "work": work.strip(), "meetings": meetings.strip(), "outcomes": outcomes.strip(), "notes": notes.strip() } try: supabase.table("logs").insert(data).execute() return "✅ Log saved successfully!" except Exception as e: return f"❌ Error saving log: {str(e)}" # ================================ # VIEW TODAY LOGS # ================================ def view_today(): today = datetime.now().strftime("%Y-%m-%d") try: res = supabase.table("logs").select("*").eq("date", today).execute() logs = res.data if not logs: return "No logs for today." logs = sorted(logs, key=lambda x: x["timestamp"]) output = "" for l in logs: output += f""" 🕒 {l['timestamp']} Work: {l['work']} Meetings: {l['meetings']} Outcomes: {l['outcomes']} Notes: {l['notes']} ------------------------- """ return output except Exception as e: return f"❌ Error fetching logs: {str(e)}" # ================================ # UI # ================================ with gr.Blocks(theme=gr.themes.Soft()) as app: gr.Markdown("# 🧠 Daily Work Logger") with gr.Tab("➕ Add Log"): work = gr.Textbox(label="Work Done", placeholder="What did you work on?", lines=3) meetings = gr.Textbox(label="Meetings", placeholder="Meetings / calls", lines=2) outcomes = gr.Textbox(label="Outcomes", placeholder="What got done?", lines=2) notes = gr.Textbox(label="Notes", placeholder="Anything else...", lines=2) submit_btn = gr.Button("💾 Save Log") status = gr.Textbox(label="Status") submit_btn.click(add_log, inputs=[work, meetings, outcomes, notes], outputs=status) with gr.Tab("📅 Today's Logs"): refresh_btn = gr.Button("🔄 Refresh") logs_display = gr.Textbox(label="Logs", lines=20) refresh_btn.click(view_today, outputs=logs_display) app.launch()