Spaces:
Sleeping
Sleeping
File size: 3,056 Bytes
8e39e8e 0e3fbad 896fdf1 0e3fbad 8e39e8e 896fdf1 8e39e8e 896fdf1 8e39e8e 896fdf1 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e 0e3fbad 8e39e8e | 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | 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() |