shruti.varghese@sandisk.com commited on
Commit
e9848db
·
1 Parent(s): 85ce402

Simplify custom UI with guided run demo flow

Browse files
Files changed (1) hide show
  1. server/ui.py +119 -131
server/ui.py CHANGED
@@ -102,6 +102,46 @@ def _format_runtime_debug(observation: dict[str, Any]) -> tuple[str, str]:
102
  return runtime_md, log_md
103
 
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  def _dropdown_update(value: str, choices: list[str]) -> dict[str, Any]:
106
  normalized_choices = [str(choice) for choice in (choices or []) if str(choice)]
107
  normalized_value = str(value or "")
@@ -115,6 +155,10 @@ def _dropdown_update(value: str, choices: list[str]) -> dict[str, Any]:
115
  return gr.update(choices=normalized_choices, value=normalized_value)
116
 
117
 
 
 
 
 
118
  def build_developer_control_room_ui(
119
  web_manager: Any,
120
  action_fields: List[Dict[str, Any]],
@@ -261,44 +305,6 @@ def build_developer_control_room_ui(
261
  }
262
  """
263
 
264
- async def reset_env(task_id: str, scenario_index: int):
265
- try:
266
- data = await web_manager.reset_environment(
267
- {"task_id": task_id, "scenario_index": scenario_index}
268
- )
269
- return (
270
- _pretty_json(data.get("observation", {})),
271
- _pretty_json(data),
272
- "Reset complete.",
273
- )
274
- except Exception as exc:
275
- return ("", "", f"Reset error: {exc}")
276
-
277
- async def step_env(action_type: str, params_json: str):
278
- try:
279
- parameters = _safe_json(params_json)
280
- except Exception as exc:
281
- return ("", "", f"Invalid JSON: {exc}")
282
-
283
- payload = {"action_type": action_type, "parameters": parameters}
284
- try:
285
- data = await web_manager.step_environment(payload)
286
- return (
287
- _pretty_json(data.get("observation", {})),
288
- _pretty_json(data),
289
- "Step complete.",
290
- )
291
- except Exception as exc:
292
- return ("", "", f"Step error: {exc}")
293
-
294
- def get_state_sync():
295
- try:
296
- state = web_manager.get_state()
297
- runtime_md, log_md = _format_runtime_debug(state)
298
- return _pretty_json(state), runtime_md, log_md, "State refreshed."
299
- except Exception as exc:
300
- return f"State error: {exc}", "Runtime status: unavailable", f"State error: {exc}", f"State error: {exc}"
301
-
302
  def on_task_change(task_id: str):
303
  scenario_ids = _scenario_ids_for_task(task_id)
304
  scenario_value = scenario_ids[0] if scenario_ids else ""
@@ -306,41 +312,66 @@ def build_developer_control_room_ui(
306
  validators = fields["validators"] or []
307
  return (
308
  _dropdown_update(scenario_value, scenario_ids),
309
- _dropdown_update(fields["source_csv"], [fields["source_csv"]]),
310
- _dropdown_update(fields["raw_table"], [fields["raw_table"]]),
311
- _dropdown_update(fields["final_view"], [fields["final_view"]]),
312
- _dropdown_update(validators[0] if validators else "", validators),
 
 
313
  )
314
 
315
  def on_scenario_change(task_id: str, scenario_id: str):
316
  fields = _simulation_fields_for(task_id, scenario_id)
317
  validators = fields["validators"] or []
318
  return (
319
- _dropdown_update(fields["source_csv"], [fields["source_csv"]]),
320
- _dropdown_update(fields["raw_table"], [fields["raw_table"]]),
321
- _dropdown_update(fields["final_view"], [fields["final_view"]]),
322
- _dropdown_update(validators[0] if validators else "", validators),
 
 
323
  )
324
 
325
- async def reset_from_preset(task_id: str, scenario_id: str):
326
  scenario_ids = _scenario_ids_for_task(task_id)
327
  scenario_index = scenario_ids.index(scenario_id) if scenario_id in scenario_ids else 0
328
- obs_json, raw, status_text = await reset_env(task_id, scenario_index)
 
 
 
 
329
  try:
330
- observation = _safe_json(obs_json)
 
 
 
331
  except Exception:
332
- observation = {}
333
- runtime_md, log_md = _format_runtime_debug(observation)
334
- return obs_json, raw, status_text, runtime_md, log_md
 
 
 
 
 
 
 
 
335
 
336
- async def step_with_debug(action_type: str, params_json: str):
337
- obs_json, raw, status_text = await step_env(action_type, params_json)
338
- try:
339
- observation = _safe_json(obs_json)
340
- except Exception:
341
- observation = {}
342
- runtime_md, log_md = _format_runtime_debug(observation)
343
- return obs_json, raw, status_text, runtime_md, log_md
 
 
 
 
 
 
344
 
345
  with gr.Blocks(title=display_title) as demo:
346
  gr.HTML(f"<style>{css}</style>")
@@ -359,117 +390,74 @@ def build_developer_control_room_ui(
359
 
360
  with gr.Row():
361
  with gr.Column(scale=3):
362
- gr.HTML("<div class='dcr-chip-row'><span class='dcr-chip'><strong>Port</strong> 7860</span><span class='dcr-chip'><strong>Mode</strong> Single-page UI</span></div>")
363
  with gr.Group(elem_classes="dcr-panel"):
364
- gr.HTML("<div class='dcr-panel-title'>Create Pipeline</div>")
365
- gr.HTML("<div class='dcr-side-note'>Select a pipeline task and scenario. Downstream fields are preset from scenario metadata.</div>")
366
  task_id = gr.Dropdown(
367
  choices=pipeline_task_ids,
368
  value=default_task_id,
369
- label="Task",
370
  )
371
  scenario_id = gr.Dropdown(
372
  choices=default_scenarios,
373
  value=default_scenario_id,
374
- label="Scenario",
375
  )
376
- source_csv = gr.Dropdown(
377
- choices=[default_fields["source_csv"]] if default_fields["source_csv"] else [""],
378
  value=default_fields["source_csv"] or "",
379
- label="Source CSV (preset)",
380
  interactive=False,
381
  )
382
- raw_table = gr.Dropdown(
383
- choices=[default_fields["raw_table"]] if default_fields["raw_table"] else [""],
384
  value=default_fields["raw_table"] or "",
385
- label="Raw Table (preset)",
386
  interactive=False,
387
  )
388
- final_view = gr.Dropdown(
389
- choices=[default_fields["final_view"]] if default_fields["final_view"] else [""],
390
  value=default_fields["final_view"] or "",
391
- label="Final View (preset)",
392
  interactive=False,
393
  )
394
- validator_profile = gr.Dropdown(
395
- choices=default_fields["validators"] or [""],
396
  value=(default_fields["validators"][0] if default_fields["validators"] else ""),
397
- label="Validator Profile (preset)",
398
  interactive=False,
399
  )
400
- reset_btn = gr.Button("Reset Episode", elem_classes="dcr-btn-secondary")
401
 
402
  with gr.Group(elem_classes="dcr-panel"):
403
- gr.HTML("<div class='dcr-panel-title'>Action Composer</div>")
404
- gr.HTML("<div class='dcr-side-note'>Use exact action names and JSON params. This is intentionally close to the raw FlowOS benchmark surface.</div>")
405
- action_type = gr.Dropdown(
406
- choices=[
407
- "search_workspace",
408
- "read_file",
409
- "inspect_schema",
410
- "inspect_lineage",
411
- "inspect_llm_draft",
412
- "edit_file",
413
- "run_validator",
414
- "submit_repair",
415
- "submit_review",
416
- "submit_workspace",
417
- ],
418
- value="read_file",
419
- label="Action Type",
420
- )
421
- params_json = gr.Code(
422
- value='{"path":"transforms/orders_daily.sql"}',
423
- label="Action Parameters (JSON)",
424
- language="json",
425
- elem_classes="dcr-json",
426
- )
427
- with gr.Row():
428
- step_btn = gr.Button("Send Action", elem_classes="dcr-btn-primary")
429
- state_btn = gr.Button("Get State", elem_classes="dcr-btn-secondary")
430
-
431
- with gr.Group(elem_classes="dcr-status"):
432
- status = gr.Textbox(label="Status", interactive=False, container=False)
433
- with gr.Group(elem_classes="dcr-panel"):
434
- gr.HTML("<div class='dcr-panel-title'>Pipeline Status / Debug Steps</div>")
435
- pipeline_runtime = gr.Markdown("Runtime status: idle")
436
- pipeline_steps = gr.Markdown("No pipeline execution yet.")
437
 
438
  with gr.Column(scale=4):
439
  with gr.Group(elem_classes="dcr-panel"):
440
- gr.HTML("<div class='dcr-panel-title'>Observation</div>")
441
- obs_display = gr.Code(label="Observation", language="json", value="")
442
- with gr.Group(elem_classes="dcr-panel"):
443
- gr.HTML("<div class='dcr-panel-title'>Raw JSON</div>")
444
- raw_json = gr.Code(label="Raw Response", language="json", value="")
 
 
445
  if quick_start_md:
446
  with gr.Group(elem_classes="dcr-panel"):
447
  gr.HTML("<div class='dcr-panel-title'>Quick Start</div>")
448
  gr.Markdown(quick_start_md)
449
 
450
- reset_btn.click(
451
- fn=reset_from_preset,
452
  inputs=[task_id, scenario_id],
453
- outputs=[obs_display, raw_json, status, pipeline_runtime, pipeline_steps],
454
- )
455
- step_btn.click(
456
- fn=step_with_debug,
457
- inputs=[action_type, params_json],
458
- outputs=[obs_display, raw_json, status, pipeline_runtime, pipeline_steps],
459
- )
460
- state_btn.click(
461
- fn=get_state_sync,
462
- outputs=[raw_json, pipeline_runtime, pipeline_steps, status],
463
  )
464
  task_id.change(
465
  fn=on_task_change,
466
  inputs=[task_id],
467
- outputs=[scenario_id, source_csv, raw_table, final_view, validator_profile],
468
  )
469
  scenario_id.change(
470
  fn=on_scenario_change,
471
  inputs=[task_id, scenario_id],
472
- outputs=[source_csv, raw_table, final_view, validator_profile],
473
  )
474
 
475
  return demo
 
102
  return runtime_md, log_md
103
 
104
 
105
+ def _friendly_status(observation: dict[str, Any], phase: str) -> str:
106
+ if not observation:
107
+ return f"Status: {phase}"
108
+ if observation.get("last_action_error"):
109
+ return f"Status: Needs attention - {observation['last_action_error']}"
110
+ if observation.get("execution_logs"):
111
+ return f"Status: {phase} - pipeline produced runtime steps."
112
+ return f"Status: {phase}"
113
+
114
+
115
+ def _compact_timeline(observation: dict[str, Any], preface_steps: list[str]) -> str:
116
+ lines = [f"{idx + 1}. {text}" for idx, text in enumerate(preface_steps)]
117
+ logs = observation.get("execution_logs") or []
118
+ if logs:
119
+ offset = len(lines)
120
+ lines.extend([f"{offset + idx + 1}. {line}" for idx, line in enumerate(logs[:12])])
121
+ if not lines:
122
+ return "No run yet. Choose task and scenario, then press Run Demo."
123
+ return "\n".join(lines)
124
+
125
+
126
+ def _demo_action_payload(fields: dict[str, Any]) -> dict[str, str]:
127
+ source_csv = fields.get("source_csv") or "data/source.csv"
128
+ raw_table = fields.get("raw_table") or "raw_demo"
129
+ final_view = fields.get("final_view") or "final_demo"
130
+ content = "\n".join(
131
+ [
132
+ f"name: {final_view}_job",
133
+ f"storage_path: mock_s3/staged/{source_csv.split('/')[-1]}",
134
+ f"raw_table: {raw_table}",
135
+ "load_sql: sql/load_raw.sql",
136
+ "build_sql: sql/build_table.sql",
137
+ "report_sql: sql/report_view.sql",
138
+ f"final_view: {final_view}",
139
+ "",
140
+ ]
141
+ )
142
+ return {"path": "pipelines/report_job.yaml", "content": content}
143
+
144
+
145
  def _dropdown_update(value: str, choices: list[str]) -> dict[str, Any]:
146
  normalized_choices = [str(choice) for choice in (choices or []) if str(choice)]
147
  normalized_value = str(value or "")
 
155
  return gr.update(choices=normalized_choices, value=normalized_value)
156
 
157
 
158
+ def _textbox_update(value: str) -> dict[str, Any]:
159
+ return gr.update(value=str(value or ""))
160
+
161
+
162
  def build_developer_control_room_ui(
163
  web_manager: Any,
164
  action_fields: List[Dict[str, Any]],
 
305
  }
306
  """
307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  def on_task_change(task_id: str):
309
  scenario_ids = _scenario_ids_for_task(task_id)
310
  scenario_value = scenario_ids[0] if scenario_ids else ""
 
312
  validators = fields["validators"] or []
313
  return (
314
  _dropdown_update(scenario_value, scenario_ids),
315
+ _textbox_update(fields["source_csv"]),
316
+ _textbox_update(fields["raw_table"]),
317
+ _textbox_update(fields["final_view"]),
318
+ _textbox_update(validators[0] if validators else ""),
319
+ "Status: Ready - press Run Demo.",
320
+ "No run yet. Choose task and scenario, then press Run Demo.",
321
  )
322
 
323
  def on_scenario_change(task_id: str, scenario_id: str):
324
  fields = _simulation_fields_for(task_id, scenario_id)
325
  validators = fields["validators"] or []
326
  return (
327
+ _textbox_update(fields["source_csv"]),
328
+ _textbox_update(fields["raw_table"]),
329
+ _textbox_update(fields["final_view"]),
330
+ _textbox_update(validators[0] if validators else ""),
331
+ "Status: Ready - press Run Demo.",
332
+ "No run yet. Choose task and scenario, then press Run Demo.",
333
  )
334
 
335
+ async def run_demo(task_id: str, scenario_id: str):
336
  scenario_ids = _scenario_ids_for_task(task_id)
337
  scenario_index = scenario_ids.index(scenario_id) if scenario_id in scenario_ids else 0
338
+ fields = _simulation_fields_for(task_id, scenario_id)
339
+ timeline_prefix = [
340
+ f"Loaded scenario `{scenario_id or 'default'}`",
341
+ "Reset environment",
342
+ ]
343
  try:
344
+ reset_data = await web_manager.reset_environment(
345
+ {"task_id": task_id, "scenario_index": scenario_index}
346
+ )
347
+ observation = reset_data.get("observation", {})
348
  except Exception:
349
+ return "Status: Needs attention - failed to reset environment.", "1. Reset failed. Please retry."
350
+
351
+ demo_steps = [
352
+ ("read_file", {"path": "docs/runtime_contract.md"}, "Reviewed runtime contract"),
353
+ ("edit_file", _demo_action_payload(fields), "Applied pipeline preset"),
354
+ ]
355
+ first_validator = (fields.get("validators") or [""])[0]
356
+ if first_validator:
357
+ demo_steps.append(
358
+ ("run_validator", {"validator": first_validator}, f"Ran validator `{first_validator}`")
359
+ )
360
 
361
+ for action_type, params, label in demo_steps:
362
+ try:
363
+ step_data = await web_manager.step_environment(
364
+ {"action_type": action_type, "parameters": params}
365
+ )
366
+ observation = step_data.get("observation", observation)
367
+ timeline_prefix.append(label)
368
+ except Exception as exc:
369
+ timeline_prefix.append(f"{label} failed: {exc}")
370
+ break
371
+
372
+ status_text = _friendly_status(observation, "Completed")
373
+ timeline_text = _compact_timeline(observation, timeline_prefix)
374
+ return status_text, timeline_text
375
 
376
  with gr.Blocks(title=display_title) as demo:
377
  gr.HTML(f"<style>{css}</style>")
 
390
 
391
  with gr.Row():
392
  with gr.Column(scale=3):
 
393
  with gr.Group(elem_classes="dcr-panel"):
394
+ gr.HTML("<div class='dcr-panel-title'>Step 1 / Step 2</div>")
395
+ gr.HTML("<div class='dcr-side-note'>Choose a pipeline task and scenario. Then run the guided demo with one click.</div>")
396
  task_id = gr.Dropdown(
397
  choices=pipeline_task_ids,
398
  value=default_task_id,
399
+ label="Step 1: Task",
400
  )
401
  scenario_id = gr.Dropdown(
402
  choices=default_scenarios,
403
  value=default_scenario_id,
404
+ label="Step 2: Scenario",
405
  )
406
+ source_csv = gr.Textbox(
 
407
  value=default_fields["source_csv"] or "",
408
+ label="Source CSV",
409
  interactive=False,
410
  )
411
+ raw_table = gr.Textbox(
 
412
  value=default_fields["raw_table"] or "",
413
+ label="Raw Table",
414
  interactive=False,
415
  )
416
+ final_view = gr.Textbox(
 
417
  value=default_fields["final_view"] or "",
418
+ label="Final View",
419
  interactive=False,
420
  )
421
+ validator_profile = gr.Textbox(
 
422
  value=(default_fields["validators"][0] if default_fields["validators"] else ""),
423
+ label="Validator Profile",
424
  interactive=False,
425
  )
426
+ run_demo_btn = gr.Button("Step 3: Run Demo", elem_classes="dcr-btn-primary")
427
 
428
  with gr.Group(elem_classes="dcr-panel"):
429
+ gr.HTML("<div class='dcr-panel-title'>Run Status</div>")
430
+ pipeline_runtime = gr.Markdown("Status: Ready - press Run Demo.")
431
+ pipeline_steps = gr.Markdown("No run yet. Choose task and scenario, then press Run Demo.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
 
433
  with gr.Column(scale=4):
434
  with gr.Group(elem_classes="dcr-panel"):
435
+ gr.HTML("<div class='dcr-panel-title'>How this works</div>")
436
+ gr.Markdown(
437
+ "1. Pick a task and scenario.\n"
438
+ "2. Review preset pipeline settings.\n"
439
+ "3. Press **Run Demo** to execute a guided run.\n\n"
440
+ "The timeline updates automatically - no manual refresh needed."
441
+ )
442
  if quick_start_md:
443
  with gr.Group(elem_classes="dcr-panel"):
444
  gr.HTML("<div class='dcr-panel-title'>Quick Start</div>")
445
  gr.Markdown(quick_start_md)
446
 
447
+ run_demo_btn.click(
448
+ fn=run_demo,
449
  inputs=[task_id, scenario_id],
450
+ outputs=[pipeline_runtime, pipeline_steps],
 
 
 
 
 
 
 
 
 
451
  )
452
  task_id.change(
453
  fn=on_task_change,
454
  inputs=[task_id],
455
+ outputs=[scenario_id, source_csv, raw_table, final_view, validator_profile, pipeline_runtime, pipeline_steps],
456
  )
457
  scenario_id.change(
458
  fn=on_scenario_change,
459
  inputs=[task_id, scenario_id],
460
+ outputs=[source_csv, raw_table, final_view, validator_profile, pipeline_runtime, pipeline_steps],
461
  )
462
 
463
  return demo