Don Rishabh Claude Opus 4.7 (1M context) commited on
Commit
e8bf76c
·
1 Parent(s): 82e3e94

demo(new-tab): also run target with verbose description

Browse files

The 'Try a new task' tab now runs the target with both the user's
verbose description AND the trained agent's compressed prompt in one
batched forward pass, so the side-by-side is visible (matching tab 1's
verbose-vs-trained framing). Adds verbose-token count next to trained-
token count.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. space-demo/app.py +35 -22
space-demo/app.py CHANGED
@@ -447,15 +447,16 @@ def generate_three(verbose_prompt: str, base_prompt: str, trained_prompt: str,
447
 
448
  def compress_and_run(description: str, budget_str: str, test_input: str):
449
  """Custom-task tab: take a free-form task description + test input,
450
- have the trained agent emit a compressed prompt, then run the target.
451
- """
 
452
  description = (description or "").strip()
453
  test_input = (test_input or "").strip()
454
  if not description:
455
- return "", "", "", "(describe your task above)"
456
  if not load_agents():
457
- return "", "", "", ("agent loading disabled — set "
458
- "DEMO_AGENT_ADAPTER to enable this tab")
459
  try:
460
  budget = int(budget_str)
461
  except (ValueError, TypeError):
@@ -488,20 +489,24 @@ def compress_and_run(description: str, budget_str: str, test_input: str):
488
  t1 = time.time()
489
  trained_prompt = extract_prompt(raw)
490
  trained_tok = count_tokens(trained_prompt)
 
491
 
492
  if test_input:
493
- outs = run_target_batch([trained_prompt], test_input)
494
- target_output = outs[0]
 
495
  t2 = time.time()
496
  msg = (
497
  f"agent: {t1-t0:.1f}s | target: {t2-t1:.1f}s | "
498
- f"trained prompt: {trained_tok} tok"
499
  )
500
  else:
501
- target_output = "(enter a test input to run the target)"
502
- msg = f"agent: {t1-t0:.1f}s | trained prompt: {trained_tok} tok"
 
503
 
504
- return trained_prompt, str(trained_tok), target_output, msg
 
505
 
506
 
507
  # ---------------------------------------------------------------------------
@@ -618,11 +623,13 @@ def build_app() -> gr.Blocks:
618
  "Describe a brand-new task, set a token budget, and "
619
  "(optionally) a test input. The trained agent will "
620
  "compress your description into a short system prompt, "
621
- "then the target runs it on your input. First click "
622
- "loads the agent + LoRA (~6 GB)."
 
 
623
  )
624
  custom_desc = gr.Textbox(
625
- label="Describe your task",
626
  lines=4,
627
  placeholder=("e.g. Classify the input email as urgent, "
628
  "normal, or spam. Output one word."),
@@ -640,18 +647,24 @@ def build_app() -> gr.Blocks:
640
  variant="primary",
641
  )
642
  with gr.Row():
643
- with gr.Column(scale=2):
644
- gr.Markdown("### Trained agent prompt")
 
 
 
 
 
 
 
 
645
  custom_prompt_out = gr.Textbox(
646
- label="prompt", lines=6, interactive=False,
647
  )
648
  custom_tok = gr.Textbox(
649
  label="tokens", interactive=False,
650
  )
651
- with gr.Column(scale=2):
652
- gr.Markdown("### Target output")
653
  custom_target_out = gr.Textbox(
654
- label="output", lines=6, interactive=False,
655
  )
656
  custom_status = gr.Textbox(label="status", interactive=False)
657
 
@@ -689,8 +702,8 @@ def build_app() -> gr.Blocks:
689
  custom_btn.click(
690
  compress_and_run,
691
  inputs=[custom_desc, custom_budget, custom_input],
692
- outputs=[custom_prompt_out, custom_tok,
693
- custom_target_out, custom_status],
694
  )
695
  app.load(select_task, inputs=[task_dd], outputs=select_outputs)
696
 
 
447
 
448
  def compress_and_run(description: str, budget_str: str, test_input: str):
449
  """Custom-task tab: take a free-form task description + test input,
450
+ have the trained agent emit a compressed prompt, then run the target
451
+ with both the user's verbose description AND the compressed prompt
452
+ so the user can see the side-by-side."""
453
  description = (description or "").strip()
454
  test_input = (test_input or "").strip()
455
  if not description:
456
+ return "", "", "", "", "", "(describe your task above)"
457
  if not load_agents():
458
+ return "", "", "", "", "", ("agent loading disabled — set "
459
+ "DEMO_AGENT_ADAPTER to enable this tab")
460
  try:
461
  budget = int(budget_str)
462
  except (ValueError, TypeError):
 
489
  t1 = time.time()
490
  trained_prompt = extract_prompt(raw)
491
  trained_tok = count_tokens(trained_prompt)
492
+ verbose_tok = count_tokens(description)
493
 
494
  if test_input:
495
+ # One batched forward pass with both prompts.
496
+ outs = run_target_batch([description, trained_prompt], test_input)
497
+ verbose_output, trained_output = outs[0], outs[1]
498
  t2 = time.time()
499
  msg = (
500
  f"agent: {t1-t0:.1f}s | target: {t2-t1:.1f}s | "
501
+ f"verbose: {verbose_tok} tok → trained: {trained_tok} tok"
502
  )
503
  else:
504
+ verbose_output = trained_output = "(enter a test input to run the target)"
505
+ msg = (f"agent: {t1-t0:.1f}s | "
506
+ f"verbose: {verbose_tok} tok → trained: {trained_tok} tok")
507
 
508
+ return (trained_prompt, str(trained_tok), str(verbose_tok),
509
+ verbose_output, trained_output, msg)
510
 
511
 
512
  # ---------------------------------------------------------------------------
 
623
  "Describe a brand-new task, set a token budget, and "
624
  "(optionally) a test input. The trained agent will "
625
  "compress your description into a short system prompt, "
626
+ "then the target runs both **your verbose description** "
627
+ "AND **the compressed prompt** on your input — so you "
628
+ "can see the side-by-side. First click loads the agent "
629
+ "+ LoRA (~6 GB)."
630
  )
631
  custom_desc = gr.Textbox(
632
+ label="Describe your task (used as the verbose prompt)",
633
  lines=4,
634
  placeholder=("e.g. Classify the input email as urgent, "
635
  "normal, or spam. Output one word."),
 
647
  variant="primary",
648
  )
649
  with gr.Row():
650
+ with gr.Column():
651
+ gr.Markdown("### Verbose (your description)")
652
+ custom_verbose_tok = gr.Textbox(
653
+ label="tokens", interactive=False,
654
+ )
655
+ custom_verbose_out = gr.Textbox(
656
+ label="target output", lines=6, interactive=False,
657
+ )
658
+ with gr.Column():
659
+ gr.Markdown("### Trained agent (compressed)")
660
  custom_prompt_out = gr.Textbox(
661
+ label="prompt", lines=4, interactive=False,
662
  )
663
  custom_tok = gr.Textbox(
664
  label="tokens", interactive=False,
665
  )
 
 
666
  custom_target_out = gr.Textbox(
667
+ label="target output", lines=6, interactive=False,
668
  )
669
  custom_status = gr.Textbox(label="status", interactive=False)
670
 
 
702
  custom_btn.click(
703
  compress_and_run,
704
  inputs=[custom_desc, custom_budget, custom_input],
705
+ outputs=[custom_prompt_out, custom_tok, custom_verbose_tok,
706
+ custom_verbose_out, custom_target_out, custom_status],
707
  )
708
  app.load(select_task, inputs=[task_dd], outputs=select_outputs)
709