Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
-
# 1.
|
| 5 |
subtask_map = {
|
| 6 |
"Security": ["Industry/peers","Find/Inquiries about Stock information", "Presentation/Stakeholders","Manage/Exploit exisiting customers", "Educate/Market on security services"],
|
| 7 |
"Leasing": ["Legal/Credit/Accounting paperwork/policy","Manage existing customers", "Proposal/Marketing report","Financial analysis", "Credit-Nhóm nợ vay", "Interview-Asset checkup-Quantitative", "Understand/Market/Educate leasing/financial services"],
|
|
@@ -14,75 +15,90 @@ subtask_map = {
|
|
| 14 |
"Interview": ["Applicant-Checkup CV", "Root-cause analyze", "STAR method for interview"]
|
| 15 |
}
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"ADHD": ["Dr Tracy", "Psychology Nation"],
|
| 22 |
-
"Technology/Data": ["SQL star", "Mysterious"],
|
| 23 |
-
"Entrepreneur": ["Brian Tracy"]
|
| 24 |
-
}
|
| 25 |
def update_subtasks(cat):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 41 |
gr.Markdown("# 🍅 Track your Knowledge & Reflection")
|
| 42 |
|
| 43 |
with gr.Row():
|
| 44 |
-
# LEFT:
|
| 45 |
with gr.Column(scale=1):
|
| 46 |
category = gr.Radio(choices=list(subtask_map.keys()), label="1. Category", value="Accountancy")
|
| 47 |
task_select = gr.Dropdown(choices=subtask_map["Accountancy"], label="2. Task")
|
| 48 |
-
|
| 49 |
-
|
| 50 |
gr.Markdown("---")
|
|
|
|
| 51 |
bg = gr.Textbox(label="Background", placeholder="Bối cảnh vấn đề...")
|
| 52 |
curr = gr.Textbox(label="Current Condition", placeholder="Tình trạng hiện tại...")
|
| 53 |
-
target = gr.Textbox(label="Goal / Target Condition", placeholder="Mục tiêu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
root = gr.Textbox(label="Root Cause Analysis", placeholder="Nguyên nhân cốt lõi (5 Whys)...")
|
| 57 |
-
confirm = gr.Textbox(label="Confirmation", placeholder="Đánh giá kết quả thực tế...")
|
| 58 |
-
follow = gr.Textbox(label="Follow-up", placeholder="Hành động tiếp theo/Phòng ngừa...")
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
df = pd.DataFrame(session_records)
|
| 63 |
-
|
| 64 |
-
file_path = "Job_Strategy_A3.xlsx"
|
| 65 |
-
df.to_excel(file_path, index=False)
|
| 66 |
-
|
| 67 |
-
return df, file_path
|
| 68 |
-
# RIGHT: Visualization
|
| 69 |
-
with gr.Column(scale=2):
|
| 70 |
gr.Markdown("### 📅 Study Log")
|
| 71 |
task_table = gr.DataFrame(
|
| 72 |
headers=["Date", "Category", "Task", "Subtask", "Background", "Current condition", "Goal/Target condition", "Root Cause Analysis", "Confirmation", "Follow-up"],
|
| 73 |
-
datatype="str",
|
| 74 |
wrap=True,
|
| 75 |
interactive=True
|
| 76 |
)
|
| 77 |
|
|
|
|
|
|
|
| 78 |
with gr.Accordion("View Knowledge Vault", open=False):
|
| 79 |
gr.Markdown("Your reflections will be archived here for 'Deep Thinking' sessions.")
|
| 80 |
vault_display = gr.Textbox(label="History Log", interactive=False, lines=10)
|
| 81 |
-
|
| 82 |
-
# Save Reflection Logic
|
| 83 |
-
def save_log(bg_val, curr_val, target_val, root_val, confirm_val, follow_val):
|
| 84 |
-
return f"BACKGROUND: {bg_val}\nCURRENT: {curr_val}\nTARGET: {target_val}\nROOT CAUSE: {root_val}\nCONFIRMATION: {confirm_val}\nFOLLOW-UP: {follow_val}\n---"
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import datetime
|
| 4 |
|
| 5 |
+
# 1. DATA STRUCTURES
|
| 6 |
subtask_map = {
|
| 7 |
"Security": ["Industry/peers","Find/Inquiries about Stock information", "Presentation/Stakeholders","Manage/Exploit exisiting customers", "Educate/Market on security services"],
|
| 8 |
"Leasing": ["Legal/Credit/Accounting paperwork/policy","Manage existing customers", "Proposal/Marketing report","Financial analysis", "Credit-Nhóm nợ vay", "Interview-Asset checkup-Quantitative", "Understand/Market/Educate leasing/financial services"],
|
|
|
|
| 15 |
"Interview": ["Applicant-Checkup CV", "Root-cause analyze", "STAR method for interview"]
|
| 16 |
}
|
| 17 |
|
| 18 |
+
# Persistent session storage
|
| 19 |
+
session_records = []
|
| 20 |
+
|
| 21 |
+
# 2. LOGIC FUNCTIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def update_subtasks(cat):
|
| 23 |
+
choices = subtask_map.get(cat, [])
|
| 24 |
+
return gr.Dropdown(choices=choices, value=choices[0] if choices else None)
|
| 25 |
+
|
| 26 |
+
def save_and_update_table(cat, task, bg, curr, target, root, confirm, follow):
|
| 27 |
+
global session_records
|
| 28 |
+
|
| 29 |
+
new_row = {
|
| 30 |
+
"Date": datetime.date.today().strftime("%d/%m"),
|
| 31 |
+
"Category": cat,
|
| 32 |
+
"Task": task,
|
| 33 |
+
"Subtask": "Deep Work",
|
| 34 |
+
"Background": bg,
|
| 35 |
+
"Current condition": curr,
|
| 36 |
+
"Goal/Target condition": target,
|
| 37 |
+
"Root Cause Analysis": root,
|
| 38 |
+
"Confirmation": confirm,
|
| 39 |
+
"Follow-up": follow
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
session_records.append(new_row)
|
| 43 |
+
df = pd.DataFrame(session_records)
|
| 44 |
+
|
| 45 |
+
# Save to Excel
|
| 46 |
+
file_path = "Job_Strategy_A3.xlsx"
|
| 47 |
+
df.to_excel(file_path, index=False)
|
| 48 |
+
|
| 49 |
+
# Update the Vault Text
|
| 50 |
+
vault_entry = f"--- {new_row['Date']} | {cat}: {task} ---\nROOT: {root}\nFOLLOW-UP: {follow}\n\n"
|
| 51 |
|
| 52 |
+
return df, file_path, vault_entry
|
| 53 |
+
|
| 54 |
+
# 3. BUILDING THE DASHBOARD
|
| 55 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 56 |
gr.Markdown("# 🍅 Track your Knowledge & Reflection")
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
+
# --- LEFT PANEL: INPUTS ---
|
| 60 |
with gr.Column(scale=1):
|
| 61 |
category = gr.Radio(choices=list(subtask_map.keys()), label="1. Category", value="Accountancy")
|
| 62 |
task_select = gr.Dropdown(choices=subtask_map["Accountancy"], label="2. Task")
|
| 63 |
+
|
|
|
|
| 64 |
gr.Markdown("---")
|
| 65 |
+
gr.Markdown("### 🛠 A3 Deep Analysis")
|
| 66 |
bg = gr.Textbox(label="Background", placeholder="Bối cảnh vấn đề...")
|
| 67 |
curr = gr.Textbox(label="Current Condition", placeholder="Tình trạng hiện tại...")
|
| 68 |
+
target = gr.Textbox(label="Goal / Target Condition", placeholder="Mục tiêu...")
|
| 69 |
+
|
| 70 |
+
with gr.Accordion("Deep Root Cause", open=False):
|
| 71 |
+
root = gr.Textbox(label="Root Cause Analysis", placeholder="5 Whys...")
|
| 72 |
+
confirm = gr.Textbox(label="Confirmation")
|
| 73 |
+
follow = gr.Textbox(label="Follow-up")
|
| 74 |
|
| 75 |
+
save_reflect = gr.Button("💾 Save Reflection & Log", variant="primary")
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
# --- RIGHT PANEL: VISUALIZATION ---
|
| 78 |
+
with gr.Column(scale=2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
gr.Markdown("### 📅 Study Log")
|
| 80 |
task_table = gr.DataFrame(
|
| 81 |
headers=["Date", "Category", "Task", "Subtask", "Background", "Current condition", "Goal/Target condition", "Root Cause Analysis", "Confirmation", "Follow-up"],
|
| 82 |
+
datatype="str",
|
| 83 |
wrap=True,
|
| 84 |
interactive=True
|
| 85 |
)
|
| 86 |
|
| 87 |
+
excel_file = gr.File(label="Download Excel report")
|
| 88 |
+
|
| 89 |
with gr.Accordion("View Knowledge Vault", open=False):
|
| 90 |
gr.Markdown("Your reflections will be archived here for 'Deep Thinking' sessions.")
|
| 91 |
vault_display = gr.Textbox(label="History Log", interactive=False, lines=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
# 4. EVENT LISTENERS
|
| 94 |
+
# Dynamic Dropdown
|
| 95 |
+
category.change(update_subtasks, inputs=[category], outputs=[task_select])
|
| 96 |
+
|
| 97 |
+
# Save Logic
|
| 98 |
+
save_reflect.click(
|
| 99 |
+
fn=save_and_update_table,
|
| 100 |
+
inputs=[category, task_select, bg, curr, target, root, confirm, follow],
|
| 101 |
+
outputs=[task_table, excel_file, vault_display]
|
| 102 |
+
)
|
| 103 |
|
| 104 |
+
demo.launch()
|