Parthps commited on
Commit
0e3fbad
Β·
verified Β·
1 Parent(s): 8e39e8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -44
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
- FILE_PATH = "work_logs.json"
7
-
8
- # Load or create file
9
- if not os.path.exists(FILE_PATH):
10
- with open(FILE_PATH, "w") as f:
11
- json.dump([], f)
12
 
13
- def load_logs():
14
- with open(FILE_PATH, "r") as f:
15
- return json.load(f)
16
 
17
- def save_logs(logs):
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
- logs = load_logs()
 
23
 
24
- entry = {
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
- logs.append(entry)
34
- save_logs(logs)
35
-
36
- return "βœ… Saved!"
 
37
 
 
 
 
38
  def view_today():
39
- logs = load_logs()
40
  today = datetime.now().strftime("%Y-%m-%d")
41
 
42
- today_logs = [l for l in logs if l["date"] == today]
 
 
 
 
 
43
 
44
- if not today_logs:
45
- return "No logs today."
46
 
47
- text = ""
48
- for l in today_logs:
49
- text += f"""
50
  πŸ•’ {l['timestamp']}
51
  Work: {l['work']}
52
  Meetings: {l['meetings']}
53
  Outcomes: {l['outcomes']}
54
  Notes: {l['notes']}
55
- ------------------
56
  """
57
- return text
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
- btn = gr.Button("Save Log")
70
- output = gr.Textbox(label="Status")
71
 
72
- btn.click(add_log, [work, meetings, outcomes, notes], output)
73
 
74
- with gr.Tab("πŸ“… Today Logs"):
75
- refresh = gr.Button("Refresh")
76
- logs_box = gr.Textbox(lines=15)
77
 
78
- refresh.click(view_today, outputs=logs_box)
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()