Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,80 +1,92 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import json
|
| 3 |
-
import os
|
| 4 |
from datetime import datetime
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
json.dump([], f)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
return json.load(f)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
with open(FILE_PATH, "w") as f:
|
| 19 |
-
json.dump(logs, f, indent=2)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
def add_log(work, meetings, outcomes, notes):
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
"date": datetime.now().strftime("%Y-%m-%d"),
|
| 26 |
"timestamp": datetime.now().strftime("%H:%M:%S"),
|
| 27 |
-
"work": work,
|
| 28 |
-
"meetings": meetings,
|
| 29 |
-
"outcomes": outcomes,
|
| 30 |
-
"notes": notes
|
| 31 |
}
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
def view_today():
|
| 39 |
-
logs = load_logs()
|
| 40 |
today = datetime.now().strftime("%Y-%m-%d")
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
return "No logs today."
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
π {l['timestamp']}
|
| 51 |
Work: {l['work']}
|
| 52 |
Meetings: {l['meetings']}
|
| 53 |
Outcomes: {l['outcomes']}
|
| 54 |
Notes: {l['notes']}
|
| 55 |
-
------------------
|
| 56 |
"""
|
| 57 |
-
|
| 58 |
|
|
|
|
|
|
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 61 |
gr.Markdown("# π§ Daily Work Logger")
|
| 62 |
|
| 63 |
with gr.Tab("β Add Log"):
|
| 64 |
-
work = gr.Textbox(label="Work Done", lines=3)
|
| 65 |
-
meetings = gr.Textbox(label="Meetings", lines=2)
|
| 66 |
-
outcomes = gr.Textbox(label="Outcomes", lines=2)
|
| 67 |
-
notes = gr.Textbox(label="Notes", lines=2)
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
with gr.Tab("π
Today Logs"):
|
| 75 |
-
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from datetime import datetime
|
| 3 |
+
from supabase import create_client
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
# ================================
|
| 7 |
+
# CONFIG (use Hugging Face Secrets)
|
| 8 |
+
# ================================
|
| 9 |
+
SUPABASE_URL = os.getenv("https://ereymjpqndjggfuakltc.supabase.co")
|
| 10 |
+
SUPABASE_KEY = os.getenv("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImVyZXltanBxbmRqZ2dmdWFrbHRjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Nzc4OTAyODMsImV4cCI6MjA5MzQ2NjI4M30.vNIIiDVDwVjzbmhAUs23vnJZmmE1buebQ8aj_xQe0PM")
|
|
|
|
| 11 |
|
| 12 |
+
if not SUPABASE_URL or not SUPABASE_KEY:
|
| 13 |
+
raise Exception("Missing Supabase credentials. Add them in Secrets.")
|
|
|
|
| 14 |
|
| 15 |
+
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# ================================
|
| 18 |
+
# ADD LOG FUNCTION
|
| 19 |
+
# ================================
|
| 20 |
def add_log(work, meetings, outcomes, notes):
|
| 21 |
+
if not work.strip():
|
| 22 |
+
return "β οΈ Please enter at least 'Work Done'"
|
| 23 |
|
| 24 |
+
data = {
|
| 25 |
"date": datetime.now().strftime("%Y-%m-%d"),
|
| 26 |
"timestamp": datetime.now().strftime("%H:%M:%S"),
|
| 27 |
+
"work": work.strip(),
|
| 28 |
+
"meetings": meetings.strip(),
|
| 29 |
+
"outcomes": outcomes.strip(),
|
| 30 |
+
"notes": notes.strip()
|
| 31 |
}
|
| 32 |
|
| 33 |
+
try:
|
| 34 |
+
supabase.table("logs").insert(data).execute()
|
| 35 |
+
return "β
Log saved successfully!"
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"β Error saving log: {str(e)}"
|
| 38 |
|
| 39 |
+
# ================================
|
| 40 |
+
# VIEW TODAY LOGS
|
| 41 |
+
# ================================
|
| 42 |
def view_today():
|
|
|
|
| 43 |
today = datetime.now().strftime("%Y-%m-%d")
|
| 44 |
|
| 45 |
+
try:
|
| 46 |
+
res = supabase.table("logs").select("*").eq("date", today).execute()
|
| 47 |
+
logs = res.data
|
| 48 |
+
|
| 49 |
+
if not logs:
|
| 50 |
+
return "No logs for today."
|
| 51 |
|
| 52 |
+
logs = sorted(logs, key=lambda x: x["timestamp"])
|
|
|
|
| 53 |
|
| 54 |
+
output = ""
|
| 55 |
+
for l in logs:
|
| 56 |
+
output += f"""
|
| 57 |
π {l['timestamp']}
|
| 58 |
Work: {l['work']}
|
| 59 |
Meetings: {l['meetings']}
|
| 60 |
Outcomes: {l['outcomes']}
|
| 61 |
Notes: {l['notes']}
|
| 62 |
+
-------------------------
|
| 63 |
"""
|
| 64 |
+
return output
|
| 65 |
|
| 66 |
+
except Exception as e:
|
| 67 |
+
return f"β Error fetching logs: {str(e)}"
|
| 68 |
|
| 69 |
+
# ================================
|
| 70 |
+
# UI
|
| 71 |
+
# ================================
|
| 72 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 73 |
gr.Markdown("# π§ Daily Work Logger")
|
| 74 |
|
| 75 |
with gr.Tab("β Add Log"):
|
| 76 |
+
work = gr.Textbox(label="Work Done", placeholder="What did you work on?", lines=3)
|
| 77 |
+
meetings = gr.Textbox(label="Meetings", placeholder="Meetings / calls", lines=2)
|
| 78 |
+
outcomes = gr.Textbox(label="Outcomes", placeholder="What got done?", lines=2)
|
| 79 |
+
notes = gr.Textbox(label="Notes", placeholder="Anything else...", lines=2)
|
| 80 |
|
| 81 |
+
submit_btn = gr.Button("πΎ Save Log")
|
| 82 |
+
status = gr.Textbox(label="Status")
|
| 83 |
|
| 84 |
+
submit_btn.click(add_log, inputs=[work, meetings, outcomes, notes], outputs=status)
|
| 85 |
|
| 86 |
+
with gr.Tab("π
Today's Logs"):
|
| 87 |
+
refresh_btn = gr.Button("π Refresh")
|
| 88 |
+
logs_display = gr.Textbox(label="Logs", lines=20)
|
| 89 |
|
| 90 |
+
refresh_btn.click(view_today, outputs=logs_display)
|
| 91 |
|
| 92 |
app.launch()
|