Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,22 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
import datetime
|
| 4 |
-
import
|
|
|
|
| 5 |
|
| 6 |
-
# 1. DATA STRUCTURES
|
| 7 |
subtask_map = {
|
| 8 |
-
"Investment": ["control and compliance","Industry/peers research","Stock information","Manage and circulate news to
|
| 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
|
| 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 |
-
|
| 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 |
-
# --- 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 |
-
|
| 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")
|
|
|