Spaces:
Sleeping
Sleeping
Rafael Poyiadzi Claude Opus 4.6 commited on
Commit ·
f3c769f
1
Parent(s): 2f173ce
Add run history dropdown, text wrapping, and PostHog debug flag
Browse files- Run history: dropdown selector preserves past run results within a session
- Dataframe: wrap=True and max_chars=200 for cleaner text display
- PostHog: POSTHOG_DEBUG env var to enable debug logging
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -20,6 +20,7 @@ _POSTHOG_ENABLED = bool(_POSTHOG_KEY and _POSTHOG_HOST)
|
|
| 20 |
posthog.api_key = _POSTHOG_KEY
|
| 21 |
posthog.project_api_key = _POSTHOG_KEY
|
| 22 |
posthog.host = _POSTHOG_HOST
|
|
|
|
| 23 |
if _POSTHOG_ENABLED:
|
| 24 |
atexit.register(posthog.shutdown)
|
| 25 |
|
|
@@ -252,7 +253,7 @@ async def run_agent_map(api_key, file, query, effort_label, fields_list, session
|
|
| 252 |
)
|
| 253 |
output_df.to_csv(tmp.name, index=False)
|
| 254 |
|
| 255 |
-
return output_df,
|
| 256 |
|
| 257 |
|
| 258 |
def _parse_research_val(val):
|
|
@@ -493,7 +494,7 @@ with gr.Blocks(
|
|
| 493 |
submit_btn = gr.Button("Run", variant="primary")
|
| 494 |
|
| 495 |
# Submit: read name/desc/opts from components for freshest values
|
| 496 |
-
async def on_submit(api_key_val, file_val, query_val, effort_val, session_id_val, *dynamic_vals):
|
| 497 |
names = dynamic_vals[:n]
|
| 498 |
descs = dynamic_vals[n:2 * n]
|
| 499 |
opts_vals = list(dynamic_vals[2 * n:])
|
|
@@ -510,16 +511,28 @@ with gr.Blocks(
|
|
| 510 |
entry["options"] = next(opts_iter, "")
|
| 511 |
fields_list.append(entry)
|
| 512 |
try:
|
| 513 |
-
result_df,
|
| 514 |
api_key_val, file_val, query_val, effort_val, fields_list, session_id_val
|
| 515 |
)
|
| 516 |
has_research = "research" in result_df.columns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
return (
|
| 518 |
gr.update(value="", visible=False),
|
| 519 |
result_df,
|
| 520 |
hide_research(result_df) if has_research else result_df,
|
| 521 |
-
|
| 522 |
gr.update(value=False, visible=has_research),
|
|
|
|
|
|
|
| 523 |
)
|
| 524 |
except gr.Error:
|
| 525 |
raise
|
|
@@ -533,23 +546,32 @@ with gr.Blocks(
|
|
| 533 |
gr.update(),
|
| 534 |
gr.update(),
|
| 535 |
gr.update(),
|
|
|
|
|
|
|
| 536 |
)
|
| 537 |
|
| 538 |
submit_btn.click(
|
| 539 |
fn=on_submit,
|
| 540 |
-
inputs=[api_key, file, query, effort, session_id] + all_text_inputs,
|
| 541 |
-
outputs=[error_box, full_results_state, output_table, download_btn, research_toggle],
|
| 542 |
)
|
| 543 |
|
| 544 |
gr.Markdown("### Results")
|
| 545 |
error_box = gr.Markdown(visible=False, elem_classes=["error-box"])
|
| 546 |
full_results_state = gr.State(None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
research_toggle = gr.Checkbox(
|
| 548 |
label="Show research details",
|
| 549 |
value=False,
|
| 550 |
visible=False,
|
| 551 |
)
|
| 552 |
-
output_table = gr.Dataframe(label="Results")
|
| 553 |
download_btn = gr.File(label="Download CSV", visible=False)
|
| 554 |
|
| 555 |
def toggle_research(show_full, full_df):
|
|
@@ -565,6 +587,31 @@ with gr.Blocks(
|
|
| 565 |
outputs=output_table,
|
| 566 |
)
|
| 567 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
def on_upload(file):
|
| 569 |
if file is None:
|
| 570 |
return gr.update(visible=False), gr.update(visible=False)
|
|
|
|
| 20 |
posthog.api_key = _POSTHOG_KEY
|
| 21 |
posthog.project_api_key = _POSTHOG_KEY
|
| 22 |
posthog.host = _POSTHOG_HOST
|
| 23 |
+
posthog.debug = os.environ.get("POSTHOG_DEBUG", "").lower() in ("1", "true", "yes")
|
| 24 |
if _POSTHOG_ENABLED:
|
| 25 |
atexit.register(posthog.shutdown)
|
| 26 |
|
|
|
|
| 253 |
)
|
| 254 |
output_df.to_csv(tmp.name, index=False)
|
| 255 |
|
| 256 |
+
return output_df, tmp.name
|
| 257 |
|
| 258 |
|
| 259 |
def _parse_research_val(val):
|
|
|
|
| 494 |
submit_btn = gr.Button("Run", variant="primary")
|
| 495 |
|
| 496 |
# Submit: read name/desc/opts from components for freshest values
|
| 497 |
+
async def on_submit(api_key_val, file_val, query_val, effort_val, session_id_val, runs_val, *dynamic_vals):
|
| 498 |
names = dynamic_vals[:n]
|
| 499 |
descs = dynamic_vals[n:2 * n]
|
| 500 |
opts_vals = list(dynamic_vals[2 * n:])
|
|
|
|
| 511 |
entry["options"] = next(opts_iter, "")
|
| 512 |
fields_list.append(entry)
|
| 513 |
try:
|
| 514 |
+
result_df, download_path = await run_agent_map(
|
| 515 |
api_key_val, file_val, query_val, effort_val, fields_list, session_id_val
|
| 516 |
)
|
| 517 |
has_research = "research" in result_df.columns
|
| 518 |
+
run_label = f"Run {len(runs_val) + 1}: {query_val[:40].strip()}"
|
| 519 |
+
if len(query_val) > 40:
|
| 520 |
+
run_label += "..."
|
| 521 |
+
new_run = {
|
| 522 |
+
"label": run_label,
|
| 523 |
+
"full_df": result_df,
|
| 524 |
+
"download_path": download_path,
|
| 525 |
+
}
|
| 526 |
+
new_runs = runs_val + [new_run]
|
| 527 |
+
run_choices = [r["label"] for r in new_runs]
|
| 528 |
return (
|
| 529 |
gr.update(value="", visible=False),
|
| 530 |
result_df,
|
| 531 |
hide_research(result_df) if has_research else result_df,
|
| 532 |
+
gr.update(value=download_path, visible=True),
|
| 533 |
gr.update(value=False, visible=has_research),
|
| 534 |
+
new_runs,
|
| 535 |
+
gr.update(choices=run_choices, value=run_label, visible=True),
|
| 536 |
)
|
| 537 |
except gr.Error:
|
| 538 |
raise
|
|
|
|
| 546 |
gr.update(),
|
| 547 |
gr.update(),
|
| 548 |
gr.update(),
|
| 549 |
+
gr.update(),
|
| 550 |
+
gr.update(),
|
| 551 |
)
|
| 552 |
|
| 553 |
submit_btn.click(
|
| 554 |
fn=on_submit,
|
| 555 |
+
inputs=[api_key, file, query, effort, session_id, runs_state] + all_text_inputs,
|
| 556 |
+
outputs=[error_box, full_results_state, output_table, download_btn, research_toggle, runs_state, run_selector],
|
| 557 |
)
|
| 558 |
|
| 559 |
gr.Markdown("### Results")
|
| 560 |
error_box = gr.Markdown(visible=False, elem_classes=["error-box"])
|
| 561 |
full_results_state = gr.State(None)
|
| 562 |
+
runs_state = gr.State([])
|
| 563 |
+
run_selector = gr.Dropdown(
|
| 564 |
+
label="Run history",
|
| 565 |
+
choices=[],
|
| 566 |
+
visible=False,
|
| 567 |
+
interactive=True,
|
| 568 |
+
)
|
| 569 |
research_toggle = gr.Checkbox(
|
| 570 |
label="Show research details",
|
| 571 |
value=False,
|
| 572 |
visible=False,
|
| 573 |
)
|
| 574 |
+
output_table = gr.Dataframe(label="Results", wrap=True, max_chars=200)
|
| 575 |
download_btn = gr.File(label="Download CSV", visible=False)
|
| 576 |
|
| 577 |
def toggle_research(show_full, full_df):
|
|
|
|
| 587 |
outputs=output_table,
|
| 588 |
)
|
| 589 |
|
| 590 |
+
def on_run_select(selected_label, runs, show_research):
|
| 591 |
+
if not selected_label or not runs:
|
| 592 |
+
return gr.update(), gr.update(), gr.update(), gr.update()
|
| 593 |
+
for r in runs:
|
| 594 |
+
if r["label"] == selected_label:
|
| 595 |
+
full_df = r["full_df"]
|
| 596 |
+
has_research = "research" in full_df.columns
|
| 597 |
+
if show_research:
|
| 598 |
+
display_df = expand_research(full_df)
|
| 599 |
+
else:
|
| 600 |
+
display_df = hide_research(full_df) if has_research else full_df
|
| 601 |
+
return (
|
| 602 |
+
full_df,
|
| 603 |
+
display_df,
|
| 604 |
+
gr.update(value=r["download_path"], visible=True),
|
| 605 |
+
gr.update(value=show_research, visible=has_research),
|
| 606 |
+
)
|
| 607 |
+
return gr.update(), gr.update(), gr.update(), gr.update()
|
| 608 |
+
|
| 609 |
+
run_selector.change(
|
| 610 |
+
on_run_select,
|
| 611 |
+
inputs=[run_selector, runs_state, research_toggle],
|
| 612 |
+
outputs=[full_results_state, output_table, download_btn, research_toggle],
|
| 613 |
+
)
|
| 614 |
+
|
| 615 |
def on_upload(file):
|
| 616 |
if file is None:
|
| 617 |
return gr.update(visible=False), gr.update(visible=False)
|