Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -148,7 +148,8 @@ def handle_parse_text(task_text, user_id):
|
|
| 148 |
"""Call Groq to classify a typed task, return pre-filled fields."""
|
| 149 |
if not task_text.strip():
|
| 150 |
return (gr.update(visible=False),
|
| 151 |
-
"", "", "Work", "Not Urgent", "Important", "Easy", 30, str(date.today()), False, "Daily", ""
|
|
|
|
| 152 |
|
| 153 |
ctx = _ensure_context(user_id)
|
| 154 |
goals = get_goals(user_id)
|
|
@@ -158,6 +159,7 @@ def handle_parse_text(task_text, user_id):
|
|
| 158 |
|
| 159 |
clarifications = result.get("clarifications_needed", [])
|
| 160 |
clar_html = ""
|
|
|
|
| 161 |
if clarifications:
|
| 162 |
items = "".join(f"<li style='margin:4px 0'>{q}</li>" for q in clarifications)
|
| 163 |
clar_html = (
|
|
@@ -184,7 +186,62 @@ def handle_parse_text(task_text, user_id):
|
|
| 184 |
str(date.today()),
|
| 185 |
False,
|
| 186 |
"Daily",
|
| 187 |
-
_ok("AI classified your task"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
)
|
| 189 |
|
| 190 |
|
|
@@ -593,6 +650,9 @@ with gr.Blocks(title="π§ Second Brain") as demo:
|
|
| 593 |
journal_hist_state = gr.State([])
|
| 594 |
journal_tasks_state = gr.State([])
|
| 595 |
journal_active = gr.State(False)
|
|
|
|
|
|
|
|
|
|
| 596 |
|
| 597 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 598 |
# AUTH SECTION
|
|
@@ -671,6 +731,15 @@ with gr.Blocks(title="π§ Second Brain") as demo:
|
|
| 671 |
with gr.Column(visible=False) as parsed_panel:
|
| 672 |
parse_status = gr.HTML("")
|
| 673 |
clar_html = gr.HTML("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
gr.HTML('<div class="sec-label" style="margin-top:12px">Review & Confirm</div>')
|
| 675 |
with gr.Row():
|
| 676 |
f_title = gr.Textbox(label="Title", scale=3)
|
|
@@ -908,7 +977,18 @@ with gr.Blocks(title="π§ Second Brain") as demo:
|
|
| 908 |
handle_parse_text,
|
| 909 |
[task_input, user_id_state],
|
| 910 |
[parsed_panel, f_title, clar_html, f_area, f_urgency, f_importance,
|
| 911 |
-
f_state, f_time, f_date, f_is_habit, f_interval, parse_status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 912 |
)
|
| 913 |
|
| 914 |
btn_transcribe.click(
|
|
|
|
| 148 |
"""Call Groq to classify a typed task, return pre-filled fields."""
|
| 149 |
if not task_text.strip():
|
| 150 |
return (gr.update(visible=False),
|
| 151 |
+
"", "", "Work", "Not Urgent", "Important", "Easy", 30, str(date.today()), False, "Daily", "",
|
| 152 |
+
gr.update(visible=False), [], "")
|
| 153 |
|
| 154 |
ctx = _ensure_context(user_id)
|
| 155 |
goals = get_goals(user_id)
|
|
|
|
| 159 |
|
| 160 |
clarifications = result.get("clarifications_needed", [])
|
| 161 |
clar_html = ""
|
| 162 |
+
has_clarifications = bool(clarifications)
|
| 163 |
if clarifications:
|
| 164 |
items = "".join(f"<li style='margin:4px 0'>{q}</li>" for q in clarifications)
|
| 165 |
clar_html = (
|
|
|
|
| 186 |
str(date.today()),
|
| 187 |
False,
|
| 188 |
"Daily",
|
| 189 |
+
_ok("AI classified your task β please answer the clarification questions above." if has_clarifications else "AI classified your task"),
|
| 190 |
+
gr.update(visible=has_clarifications), # clar_reply_row
|
| 191 |
+
clarifications, # clar_questions_state
|
| 192 |
+
task_text, # original_task_state
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def handle_clarification_reply(user_reply, original_task, clarifications, user_id):
|
| 197 |
+
"""Re-run Groq classification with the original task + clarification Q&A appended."""
|
| 198 |
+
if not user_reply.strip():
|
| 199 |
+
return (gr.update(), gr.update(), gr.update(), gr.update(),
|
| 200 |
+
gr.update(), gr.update(), gr.update(), gr.update(visible=True), "")
|
| 201 |
+
|
| 202 |
+
ctx = _ensure_context(user_id)
|
| 203 |
+
goals = get_goals(user_id)
|
| 204 |
+
areas = get_life_area_names(user_id) if user_id else []
|
| 205 |
+
|
| 206 |
+
# Build enriched task description: original + each clarification + the user's answer
|
| 207 |
+
q_block = "\n".join(f"Q: {q}" for q in clarifications)
|
| 208 |
+
enriched = (
|
| 209 |
+
f"{original_task}\n\n"
|
| 210 |
+
f"Additional context from user (answers to clarification questions):\n"
|
| 211 |
+
f"{q_block}\n"
|
| 212 |
+
f"A: {user_reply}"
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
result = parse_task_with_groq(enriched, ctx, goals, areas)
|
| 216 |
+
|
| 217 |
+
# If AI still has clarifications, show them; otherwise hide the clarification row
|
| 218 |
+
remaining = result.get("clarifications_needed", [])
|
| 219 |
+
if remaining:
|
| 220 |
+
items = "".join(f"<li style='margin:4px 0'>{q}</li>" for q in remaining)
|
| 221 |
+
clar_html_val = (
|
| 222 |
+
f'<div style="margin:10px 0;padding:12px;background:#0c0f1a;'
|
| 223 |
+
f'border-left:3px solid #a78bfa;border-radius:8px">'
|
| 224 |
+
f'<div style="color:#a78bfa;font-size:11px;font-weight:600;margin-bottom:6px">β Please clarify:</div>'
|
| 225 |
+
f'<ul style="color:#94a3b8;font-size:13px;margin:0;padding-left:16px">{items}</ul></div>'
|
| 226 |
+
)
|
| 227 |
+
clar_row_visible = True
|
| 228 |
+
else:
|
| 229 |
+
clar_html_val = '<span style="color:#4ade80;font-size:13px">β Clarified β classification updated!</span>'
|
| 230 |
+
clar_row_visible = False
|
| 231 |
+
|
| 232 |
+
area_choices = areas if areas else ["Work","Health","Finance","Learning","Personal","Family","Other"]
|
| 233 |
+
area_val = result.get("life_area") or (area_choices[0] if area_choices else "Work")
|
| 234 |
+
|
| 235 |
+
return (
|
| 236 |
+
result.get("title", original_task),
|
| 237 |
+
clar_html_val,
|
| 238 |
+
area_val,
|
| 239 |
+
result.get("urgency", "Not Urgent"),
|
| 240 |
+
result.get("importance", "Important"),
|
| 241 |
+
result.get("state_of_mind", "Easy"),
|
| 242 |
+
int(result.get("time_estimate") or 30),
|
| 243 |
+
gr.update(visible=clar_row_visible),
|
| 244 |
+
remaining,
|
| 245 |
)
|
| 246 |
|
| 247 |
|
|
|
|
| 650 |
journal_hist_state = gr.State([])
|
| 651 |
journal_tasks_state = gr.State([])
|
| 652 |
journal_active = gr.State(False)
|
| 653 |
+
# Clarification states
|
| 654 |
+
clar_questions_state = gr.State([])
|
| 655 |
+
original_task_state = gr.State("")
|
| 656 |
|
| 657 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 658 |
# AUTH SECTION
|
|
|
|
| 731 |
with gr.Column(visible=False) as parsed_panel:
|
| 732 |
parse_status = gr.HTML("")
|
| 733 |
clar_html = gr.HTML("")
|
| 734 |
+
# ββ Clarification reply row (shown only when AI has questions) ββ
|
| 735 |
+
with gr.Column(visible=False) as clar_reply_row:
|
| 736 |
+
gr.HTML('<div class="sec-label" style="margin-top:8px">Your Answer</div>')
|
| 737 |
+
clar_reply_input = gr.Textbox(
|
| 738 |
+
label="",
|
| 739 |
+
placeholder="e.g. It's for a client deadline, very high priority, should take about 2 hours",
|
| 740 |
+
lines=2
|
| 741 |
+
)
|
| 742 |
+
btn_clar_submit = gr.Button("π Re-classify with my answer", elem_classes="btn-accent")
|
| 743 |
gr.HTML('<div class="sec-label" style="margin-top:12px">Review & Confirm</div>')
|
| 744 |
with gr.Row():
|
| 745 |
f_title = gr.Textbox(label="Title", scale=3)
|
|
|
|
| 977 |
handle_parse_text,
|
| 978 |
[task_input, user_id_state],
|
| 979 |
[parsed_panel, f_title, clar_html, f_area, f_urgency, f_importance,
|
| 980 |
+
f_state, f_time, f_date, f_is_habit, f_interval, parse_status,
|
| 981 |
+
clar_reply_row, clar_questions_state, original_task_state]
|
| 982 |
+
)
|
| 983 |
+
|
| 984 |
+
btn_clar_submit.click(
|
| 985 |
+
handle_clarification_reply,
|
| 986 |
+
[clar_reply_input, original_task_state, clar_questions_state, user_id_state],
|
| 987 |
+
[f_title, clar_html, f_area, f_urgency, f_importance,
|
| 988 |
+
f_state, f_time, clar_reply_row, clar_questions_state]
|
| 989 |
+
).then(
|
| 990 |
+
lambda: "",
|
| 991 |
+
outputs=[clar_reply_input]
|
| 992 |
)
|
| 993 |
|
| 994 |
btn_transcribe.click(
|