ngocng19 commited on
Commit
81af267
·
verified ·
1 Parent(s): a70e11e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -90
app.py CHANGED
@@ -1,38 +1,22 @@
1
- import gradio as gr
2
- import pandas as pd
3
  import datetime
4
- import os
 
5
 
6
- # 1. DATA STRUCTURES
7
  subtask_map = {
8
- "Investment": ["control and compliance","Industry/peers research","Stock information","Manage and circulate news to exisiting customers","Selling"],
9
- "Leasing": ["Investment efficiency","Credit-Nhóm nợ vay", "Debt collect and check-up for business feasibility"],
10
- "Admin-Payment/Payroll": ["Chamber's social and communication","Inquiries/Billings/Invoices", "Payment/Banking", "Accounting Schedules","managed Stakeholders"],
11
  "Psychology": ["Psychology", "Reflection-Journal", "Deep thinking"],
12
  "ADHD": ["Focus Strategies", "Workflow", "Organization", "Deep-thinking/Cognitive", "Stressed/Burnout"],
13
  "Soft skill": ["Networking-Linkedin"],
14
- "Technology": ["Excel Automation","Data cleaning and manipulation", "AI skills"],
15
- }
16
-
17
- training_map = {
18
- "Softskill": ["Communciation effectively/On-point"],
19
- "Working" : ["80/20", "Flow", "Prioritization"],
20
- "Psy": ["Mental Health", "Design thinking"],
21
- "ADHD": ["Autism","Cognitive", "Feelings"],
22
- "Mindset": ["Positivity mindset", "Shift your mindset"],
23
  }
24
 
25
- # Persistent session storage
26
- session_records = []
27
-
28
- # 2. LOGIC FUNCTIONS
29
  def update_subtasks(cat):
30
  choices = subtask_map.get(cat, [])
31
  return gr.Dropdown(choices=choices, value=choices[0] if choices else None)
32
 
33
- def save_and_update_table(cat, task, bg, curr, target, root, confirm, follow):
34
- global session_records
35
-
36
  new_row = {
37
  "Date": datetime.date.today().strftime("%d/%m"),
38
  "Category": cat,
@@ -44,73 +28,51 @@ def save_and_update_table(cat, task, bg, curr, target, root, confirm, follow):
44
  "Confirmation": confirm,
45
  "Follow-up": follow
46
  }
 
 
47
 
48
- session_records.append(new_row)
49
- df = pd.DataFrame(session_records)
50
-
51
- # Save to Excel
52
- file_path = "Job_Strategy_A3.xlsx"
53
- df.to_excel(file_path, index=False)
54
-
55
- # Update the Vault Text
56
- vault_entry = ""
57
- for rec in reversed(session_records): # Show latest first
58
- vault_entry += f"--- {rec['Date']} | {rec['Category']}: {rec['Task']} ---\nROOT: {rec['Root Cause Analysis']}\nFOLLOW-UP: {rec['Follow-up']}\n\n"
59
-
60
- return df, file_path, vault_entry
61
-
62
- # 3. BUILDING THE DASHBOARD
63
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
64
- gr.Markdown("# 🍅 Track your Knowledge & Reflection")
65
-
66
- with gr.Row():
67
- # --- LEFT PANEL: INPUTS ---
68
- with gr.Column(scale=1):
69
- category = gr.Radio(choices=list(subtask_map.keys()), label="1. Category", value="Accountancy")
70
- task_select = gr.Dropdown(choices=subtask_map["Accountancy"], label="2. Task")
71
-
72
- gr.Markdown("---")
73
- gr.Markdown("### 🛠 Deep Analysis")
74
- bg = gr.Textbox(label="Background", placeholder="Bối cảnh vấn đề...")
75
- curr = gr.Textbox(label="Current Condition", placeholder="Tình trạng hiện tại...")
76
- target = gr.Textbox(label="Goal / Target Condition", placeholder="Mục tiêu...")
77
-
78
- with gr.Accordion("Deep Root Cause (5 Whys)", open=False):
79
- root = gr.Textbox(label="Root Cause Analysis", placeholder="Why? Why? Why?...")
80
- confirm = gr.Textbox(label="Confirmation")
81
- follow = gr.Textbox(label="Follow-up")
82
-
83
- save_reflect = gr.Button("💾 Save Reflection & Log", variant="primary")
84
-
85
- gr.Markdown("---")
86
- gr.Markdown("### 📚 Training & Framework")
87
- training = gr.Dropdown(choices=list(training_map.keys()), label="Training Category")
88
- training_task = gr.Textbox(label="What is your training?", placeholder="e.g. SQL Optimization")
89
- suggestion_url = gr.Textbox(label="URL / Resource")
90
-
91
- # --- RIGHT PANEL: VISUALIZATION ---
92
- with gr.Column(scale=2):
93
- gr.Markdown("### 📅 Study Log")
94
- task_table = gr.DataFrame(
95
- headers=["Date", "Category", "Task", "Background", "Current condition", "Goal/Target condition", "Root Cause Analysis", "Confirmation", "Follow-up"],
96
- datatype="str",
97
- interactive=False
98
- )
99
-
100
- excel_file = gr.File(label="Download Excel Report")
101
-
102
- with gr.Accordion("View Knowledge Vault", open=True):
103
- gr.Markdown("Your reflections archived for 'Deep Thinking' sessions:")
104
- vault_display = gr.Textbox(label="History Log", interactive=False, lines=15)
105
-
106
- # 4. EVENT LISTENERS
107
- category.change(update_subtasks, inputs=[category], outputs=[task_select])
108
 
109
- save_reflect.click(
110
- fn=save_and_update_table,
111
- inputs=[category, task_select, bg, curr, target, root, confirm, follow],
112
- outputs=[task_table, excel_file, vault_display]
113
- )
114
 
115
- if __name__ == "__main__":
116
- demo.launch()
 
 
 
1
  import datetime
2
+ import gradio as gr
3
+ import time
4
 
 
5
  subtask_map = {
6
+ "Investment": ["control and compliance", "Industry/peers research", "Stock information", "Manage and circulate news to existing customers", "Selling"],
7
+ "Leasing": ["Investment efficiency", "Credit-Nhóm nợ vay", "Debt collect and check-up for business feasibility"],
8
+ "Admin-Payment/Payroll": ["Chamber's social and communication", "Inquiries/Billings/Invoices", "Payment/Banking", "Accounting Schedules", "managed Stakeholders"],
9
  "Psychology": ["Psychology", "Reflection-Journal", "Deep thinking"],
10
  "ADHD": ["Focus Strategies", "Workflow", "Organization", "Deep-thinking/Cognitive", "Stressed/Burnout"],
11
  "Soft skill": ["Networking-Linkedin"],
12
+ "Technology": ["Excel Automation", "Data cleaning and manipulation", "AI skills"],
 
 
 
 
 
 
 
 
13
  }
14
 
 
 
 
 
15
  def update_subtasks(cat):
16
  choices = subtask_map.get(cat, [])
17
  return gr.Dropdown(choices=choices, value=choices[0] if choices else None)
18
 
19
+ def track_task(cat, task, bg, curr, target, root, confirm, follow):
 
 
20
  new_row = {
21
  "Date": datetime.date.today().strftime("%d/%m"),
22
  "Category": cat,
 
28
  "Confirmation": confirm,
29
  "Follow-up": follow
30
  }
31
+ # Save new_row to a database or a file
32
+ print(new_row) # For demonstration purposes
33
 
34
+ def handle_timer(duration, current_task):
35
+ if not current_task:
36
+ yield "00:00", "⚠️ Please select a task!"
37
+ return
38
+
39
+ secs = duration * 60
40
+ while secs >= 0:
41
+ mins, s = divmod(secs, 60)
42
+ time_str = f"{mins:02d}:{s:02d}"
43
+ yield time_str, f"🔥 Focusing on: {current_task}"
44
+ time.sleep(1) # Sleep for 1 second to create the timer effect
45
+ secs -= 1
46
+ yield "00:00", "✅ Session Complete! Take a break."
47
+
48
+ def start_pomodoro(duration, current_task):
49
+ return handle_timer(duration, current_task)
50
+
51
+ with gr.Blocks() as demo:
52
+ category = gr.Dropdown(choices=list(subtask_map.keys()), label="Select Category")
53
+ subtask = update_subtasks(category)
54
+ task = gr.Textbox(label="Task")
55
+ bg = gr.Textbox(label="Background")
56
+ curr = gr.Textbox(label="Current Condition")
57
+ target = gr.Textbox(label="Goal/Target Condition")
58
+ root = gr.Textbox(label="Root Cause Analysis")
59
+ confirm = gr.Checkbox(label="Confirmation")
60
+ follow = gr.Textbox(label="Follow-up Actions")
61
+
62
+ submit_btn = gr.Button("Submit Task")
63
+ submit_btn.click(track_task, inputs=[category, subtask, bg, curr, target, root, confirm, follow])
64
+ duration = gr.Slider(minimum=1, maximum=60, label="Duration (minutes)", value=25) # Default to 25 minutes
65
+ task = gr.Textbox(label="Current Task")
66
+ timer_output = gr.Textbox(label="Timer")
67
+ status_output = gr.Textbox(label="Status Message")
68
+
69
+ start_button = gr.Button("Start Pomodoro")
70
+ start_button.click(start_pomodoro, inputs=[duration, task], outputs=[timer_output, status_output])
71
+
72
+ with gr.Output():
73
+ for time_remaining, status in start_pomodoro(duration.value, task.value):
74
+ timer_output.update(time_remaining)
75
+ status_output.update(status)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
 
 
 
 
 
77
 
78
+ demo.launch(share="true")