Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|