Spaces:
Sleeping
Sleeping
shruti.varghese@sandisk.com commited on
Commit ·
b617763
1
Parent(s): 4ee26c3
ui changes
Browse files- server/ui.py +195 -21
server/ui.py
CHANGED
|
@@ -7,6 +7,11 @@ from typing import Any, Dict, List, Optional
|
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def _pretty_json(payload: Dict[str, Any]) -> str:
|
| 12 |
return json.dumps(payload, indent=2, ensure_ascii=False)
|
|
@@ -19,6 +24,84 @@ def _safe_json(text: str) -> Dict[str, Any]:
|
|
| 19 |
return json.loads(text)
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def build_developer_control_room_ui(
|
| 23 |
web_manager: Any,
|
| 24 |
action_fields: List[Dict[str, Any]],
|
|
@@ -30,6 +113,17 @@ def build_developer_control_room_ui(
|
|
| 30 |
del action_fields, is_chat_env
|
| 31 |
|
| 32 |
display_title = title
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
css = """
|
| 35 |
:root {
|
|
@@ -186,9 +280,54 @@ def build_developer_control_room_ui(
|
|
| 186 |
|
| 187 |
def get_state_sync():
|
| 188 |
try:
|
| 189 |
-
|
|
|
|
|
|
|
| 190 |
except Exception as exc:
|
| 191 |
-
return f"State error: {exc}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
with gr.Blocks(title=display_title) as demo:
|
| 194 |
gr.HTML(f"<style>{css}</style>")
|
|
@@ -196,7 +335,7 @@ def build_developer_control_room_ui(
|
|
| 196 |
f"""
|
| 197 |
<section class="dcr-hero">
|
| 198 |
<div class="dcr-kicker">FlowOS / Interactive Workspace / End-to-End Ops</div>
|
| 199 |
-
<div class="dcr-title">
|
| 200 |
<div class="dcr-subtitle">
|
| 201 |
Explore repair, review, and shipping in one live operating environment.
|
| 202 |
FlowOS is built to evaluate how AI agents move real work from broken to shipped.
|
|
@@ -209,21 +348,42 @@ def build_developer_control_room_ui(
|
|
| 209 |
with gr.Column(scale=3):
|
| 210 |
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>")
|
| 211 |
with gr.Group(elem_classes="dcr-panel"):
|
| 212 |
-
gr.HTML("<div class='dcr-panel-title'>
|
| 213 |
-
gr.HTML("<div class='dcr-side-note'>
|
| 214 |
task_id = gr.Dropdown(
|
| 215 |
-
choices=
|
| 216 |
-
|
| 217 |
-
"repair_pipeline_execution",
|
| 218 |
-
"review_ai_patch_safety",
|
| 219 |
-
"review_ai_patch_correctness",
|
| 220 |
-
"synthesize_reporting_asset",
|
| 221 |
-
"synthesize_data_product",
|
| 222 |
-
],
|
| 223 |
-
value="repair_data_transform",
|
| 224 |
label="Task",
|
| 225 |
)
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
reset_btn = gr.Button("Reset Episode", elem_classes="dcr-btn-secondary")
|
| 228 |
|
| 229 |
with gr.Group(elem_classes="dcr-panel"):
|
|
@@ -257,6 +417,10 @@ def build_developer_control_room_ui(
|
|
| 257 |
|
| 258 |
with gr.Group(elem_classes="dcr-status"):
|
| 259 |
status = gr.Textbox(label="Status", interactive=False, container=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
with gr.Column(scale=4):
|
| 262 |
with gr.Group(elem_classes="dcr-panel"):
|
|
@@ -271,18 +435,28 @@ def build_developer_control_room_ui(
|
|
| 271 |
gr.Markdown(quick_start_md)
|
| 272 |
|
| 273 |
reset_btn.click(
|
| 274 |
-
fn=
|
| 275 |
-
inputs=[task_id,
|
| 276 |
-
outputs=[obs_display, raw_json, status],
|
| 277 |
)
|
| 278 |
step_btn.click(
|
| 279 |
-
fn=
|
| 280 |
inputs=[action_type, params_json],
|
| 281 |
-
outputs=[obs_display, raw_json, status],
|
| 282 |
)
|
| 283 |
state_btn.click(
|
| 284 |
fn=get_state_sync,
|
| 285 |
-
outputs=[raw_json],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
)
|
| 287 |
|
| 288 |
return demo
|
|
|
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
+
try:
|
| 11 |
+
from ..tasks import get_scenario, get_task
|
| 12 |
+
except ImportError:
|
| 13 |
+
from tasks import get_scenario, get_task
|
| 14 |
+
|
| 15 |
|
| 16 |
def _pretty_json(payload: Dict[str, Any]) -> str:
|
| 17 |
return json.dumps(payload, indent=2, ensure_ascii=False)
|
|
|
|
| 24 |
return json.loads(text)
|
| 25 |
|
| 26 |
|
| 27 |
+
def _scenario_ids_for_task(task_id: str) -> list[str]:
|
| 28 |
+
try:
|
| 29 |
+
task = get_task(task_id)
|
| 30 |
+
except Exception:
|
| 31 |
+
return []
|
| 32 |
+
scenario_ids = task.get("scenario_ids") or []
|
| 33 |
+
return [str(sid) for sid in scenario_ids]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _pipeline_task_choices() -> list[str]:
|
| 37 |
+
candidate_ids = [
|
| 38 |
+
"simulate_csv_report_workflow",
|
| 39 |
+
"simulate_csv_report_curriculum_generate",
|
| 40 |
+
"simulate_csv_report_curriculum_repair",
|
| 41 |
+
]
|
| 42 |
+
valid: list[str] = []
|
| 43 |
+
for task_id in candidate_ids:
|
| 44 |
+
if _scenario_ids_for_task(task_id):
|
| 45 |
+
valid.append(task_id)
|
| 46 |
+
return valid
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _simulation_fields_for(task_id: str, scenario_id: str) -> dict[str, Any]:
|
| 50 |
+
scenario_ids = _scenario_ids_for_task(task_id)
|
| 51 |
+
if scenario_id not in scenario_ids:
|
| 52 |
+
return {
|
| 53 |
+
"source_csv": "",
|
| 54 |
+
"raw_table": "",
|
| 55 |
+
"final_view": "",
|
| 56 |
+
"validators": [],
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
scenario_index = scenario_ids.index(scenario_id)
|
| 61 |
+
scenario = get_scenario(task_id, scenario_index)
|
| 62 |
+
except Exception:
|
| 63 |
+
return {
|
| 64 |
+
"source_csv": "",
|
| 65 |
+
"raw_table": "",
|
| 66 |
+
"final_view": "",
|
| 67 |
+
"validators": [],
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
target = scenario.get("simulation_target", {})
|
| 71 |
+
return {
|
| 72 |
+
"source_csv": str(target.get("source_csv", "")),
|
| 73 |
+
"raw_table": str(target.get("expected_raw_table", {}).get("name", "")),
|
| 74 |
+
"final_view": str(target.get("expected_final_view", {}).get("name", "")),
|
| 75 |
+
"validators": [str(v) for v in scenario.get("available_validators", [])],
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def _format_runtime_debug(observation: dict[str, Any]) -> tuple[str, str]:
|
| 80 |
+
if not observation:
|
| 81 |
+
return "Runtime status: idle", "No pipeline execution yet."
|
| 82 |
+
|
| 83 |
+
runtime_status = observation.get("runtime_status") or {}
|
| 84 |
+
logs = observation.get("execution_logs") or []
|
| 85 |
+
step_count = observation.get("step_count", 0)
|
| 86 |
+
last_error = observation.get("last_action_error")
|
| 87 |
+
|
| 88 |
+
status_parts = [f"**Step:** {step_count}"]
|
| 89 |
+
if runtime_status:
|
| 90 |
+
status_parts.append(f"**Runtime:** `{json.dumps(runtime_status, ensure_ascii=False)}`")
|
| 91 |
+
else:
|
| 92 |
+
status_parts.append("**Runtime:** idle")
|
| 93 |
+
if last_error:
|
| 94 |
+
status_parts.append(f"**Error:** `{last_error}`")
|
| 95 |
+
runtime_md = " | ".join(status_parts)
|
| 96 |
+
|
| 97 |
+
if not logs:
|
| 98 |
+
log_md = "No pipeline execution yet."
|
| 99 |
+
else:
|
| 100 |
+
rendered = [f"{idx + 1}. {line}" for idx, line in enumerate(logs)]
|
| 101 |
+
log_md = "\n".join(rendered[-25:])
|
| 102 |
+
return runtime_md, log_md
|
| 103 |
+
|
| 104 |
+
|
| 105 |
def build_developer_control_room_ui(
|
| 106 |
web_manager: Any,
|
| 107 |
action_fields: List[Dict[str, Any]],
|
|
|
|
| 113 |
del action_fields, is_chat_env
|
| 114 |
|
| 115 |
display_title = title
|
| 116 |
+
pipeline_task_ids = _pipeline_task_choices()
|
| 117 |
+
if not pipeline_task_ids:
|
| 118 |
+
pipeline_task_ids = ["simulate_csv_report_workflow"]
|
| 119 |
+
default_task_id = (
|
| 120 |
+
"simulate_csv_report_workflow"
|
| 121 |
+
if "simulate_csv_report_workflow" in pipeline_task_ids
|
| 122 |
+
else (pipeline_task_ids[0] if pipeline_task_ids else "simulate_csv_report_workflow")
|
| 123 |
+
)
|
| 124 |
+
default_scenarios = _scenario_ids_for_task(default_task_id)
|
| 125 |
+
default_scenario_id = default_scenarios[0] if default_scenarios else ""
|
| 126 |
+
default_fields = _simulation_fields_for(default_task_id, default_scenario_id)
|
| 127 |
|
| 128 |
css = """
|
| 129 |
:root {
|
|
|
|
| 280 |
|
| 281 |
def get_state_sync():
|
| 282 |
try:
|
| 283 |
+
state = web_manager.get_state()
|
| 284 |
+
runtime_md, log_md = _format_runtime_debug(state)
|
| 285 |
+
return _pretty_json(state), runtime_md, log_md, "State refreshed."
|
| 286 |
except Exception as exc:
|
| 287 |
+
return f"State error: {exc}", "Runtime status: unavailable", f"State error: {exc}", f"State error: {exc}"
|
| 288 |
+
|
| 289 |
+
def on_task_change(task_id: str):
|
| 290 |
+
scenario_ids = _scenario_ids_for_task(task_id)
|
| 291 |
+
scenario_value = scenario_ids[0] if scenario_ids else ""
|
| 292 |
+
fields = _simulation_fields_for(task_id, scenario_value)
|
| 293 |
+
validators = fields["validators"] or [""]
|
| 294 |
+
return (
|
| 295 |
+
gr.Dropdown(choices=scenario_ids, value=scenario_value),
|
| 296 |
+
gr.Dropdown(choices=[fields["source_csv"]] if fields["source_csv"] else [""], value=fields["source_csv"] or ""),
|
| 297 |
+
gr.Dropdown(choices=[fields["raw_table"]] if fields["raw_table"] else [""], value=fields["raw_table"] or ""),
|
| 298 |
+
gr.Dropdown(choices=[fields["final_view"]] if fields["final_view"] else [""], value=fields["final_view"] or ""),
|
| 299 |
+
gr.Dropdown(choices=validators, value=validators[0]),
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
def on_scenario_change(task_id: str, scenario_id: str):
|
| 303 |
+
fields = _simulation_fields_for(task_id, scenario_id)
|
| 304 |
+
validators = fields["validators"] or [""]
|
| 305 |
+
return (
|
| 306 |
+
gr.Dropdown(choices=[fields["source_csv"]] if fields["source_csv"] else [""], value=fields["source_csv"] or ""),
|
| 307 |
+
gr.Dropdown(choices=[fields["raw_table"]] if fields["raw_table"] else [""], value=fields["raw_table"] or ""),
|
| 308 |
+
gr.Dropdown(choices=[fields["final_view"]] if fields["final_view"] else [""], value=fields["final_view"] or ""),
|
| 309 |
+
gr.Dropdown(choices=validators, value=validators[0]),
|
| 310 |
+
)
|
| 311 |
+
|
| 312 |
+
async def reset_from_preset(task_id: str, scenario_id: str):
|
| 313 |
+
scenario_ids = _scenario_ids_for_task(task_id)
|
| 314 |
+
scenario_index = scenario_ids.index(scenario_id) if scenario_id in scenario_ids else 0
|
| 315 |
+
obs_json, raw, status_text = await reset_env(task_id, scenario_index)
|
| 316 |
+
try:
|
| 317 |
+
observation = _safe_json(obs_json)
|
| 318 |
+
except Exception:
|
| 319 |
+
observation = {}
|
| 320 |
+
runtime_md, log_md = _format_runtime_debug(observation)
|
| 321 |
+
return obs_json, raw, status_text, runtime_md, log_md
|
| 322 |
+
|
| 323 |
+
async def step_with_debug(action_type: str, params_json: str):
|
| 324 |
+
obs_json, raw, status_text = await step_env(action_type, params_json)
|
| 325 |
+
try:
|
| 326 |
+
observation = _safe_json(obs_json)
|
| 327 |
+
except Exception:
|
| 328 |
+
observation = {}
|
| 329 |
+
runtime_md, log_md = _format_runtime_debug(observation)
|
| 330 |
+
return obs_json, raw, status_text, runtime_md, log_md
|
| 331 |
|
| 332 |
with gr.Blocks(title=display_title) as demo:
|
| 333 |
gr.HTML(f"<style>{css}</style>")
|
|
|
|
| 335 |
f"""
|
| 336 |
<section class="dcr-hero">
|
| 337 |
<div class="dcr-kicker">FlowOS / Interactive Workspace / End-to-End Ops</div>
|
| 338 |
+
<div class="dcr-title">flowOS</div>
|
| 339 |
<div class="dcr-subtitle">
|
| 340 |
Explore repair, review, and shipping in one live operating environment.
|
| 341 |
FlowOS is built to evaluate how AI agents move real work from broken to shipped.
|
|
|
|
| 348 |
with gr.Column(scale=3):
|
| 349 |
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>")
|
| 350 |
with gr.Group(elem_classes="dcr-panel"):
|
| 351 |
+
gr.HTML("<div class='dcr-panel-title'>Create Pipeline</div>")
|
| 352 |
+
gr.HTML("<div class='dcr-side-note'>Select a pipeline task and scenario. Downstream fields are preset from scenario metadata.</div>")
|
| 353 |
task_id = gr.Dropdown(
|
| 354 |
+
choices=pipeline_task_ids,
|
| 355 |
+
value=default_task_id,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
label="Task",
|
| 357 |
)
|
| 358 |
+
scenario_id = gr.Dropdown(
|
| 359 |
+
choices=default_scenarios,
|
| 360 |
+
value=default_scenario_id,
|
| 361 |
+
label="Scenario",
|
| 362 |
+
)
|
| 363 |
+
source_csv = gr.Dropdown(
|
| 364 |
+
choices=[default_fields["source_csv"]] if default_fields["source_csv"] else [""],
|
| 365 |
+
value=default_fields["source_csv"] or "",
|
| 366 |
+
label="Source CSV (preset)",
|
| 367 |
+
interactive=False,
|
| 368 |
+
)
|
| 369 |
+
raw_table = gr.Dropdown(
|
| 370 |
+
choices=[default_fields["raw_table"]] if default_fields["raw_table"] else [""],
|
| 371 |
+
value=default_fields["raw_table"] or "",
|
| 372 |
+
label="Raw Table (preset)",
|
| 373 |
+
interactive=False,
|
| 374 |
+
)
|
| 375 |
+
final_view = gr.Dropdown(
|
| 376 |
+
choices=[default_fields["final_view"]] if default_fields["final_view"] else [""],
|
| 377 |
+
value=default_fields["final_view"] or "",
|
| 378 |
+
label="Final View (preset)",
|
| 379 |
+
interactive=False,
|
| 380 |
+
)
|
| 381 |
+
validator_profile = gr.Dropdown(
|
| 382 |
+
choices=default_fields["validators"] or [""],
|
| 383 |
+
value=(default_fields["validators"][0] if default_fields["validators"] else ""),
|
| 384 |
+
label="Validator Profile (preset)",
|
| 385 |
+
interactive=False,
|
| 386 |
+
)
|
| 387 |
reset_btn = gr.Button("Reset Episode", elem_classes="dcr-btn-secondary")
|
| 388 |
|
| 389 |
with gr.Group(elem_classes="dcr-panel"):
|
|
|
|
| 417 |
|
| 418 |
with gr.Group(elem_classes="dcr-status"):
|
| 419 |
status = gr.Textbox(label="Status", interactive=False, container=False)
|
| 420 |
+
with gr.Group(elem_classes="dcr-panel"):
|
| 421 |
+
gr.HTML("<div class='dcr-panel-title'>Pipeline Status / Debug Steps</div>")
|
| 422 |
+
pipeline_runtime = gr.Markdown("Runtime status: idle")
|
| 423 |
+
pipeline_steps = gr.Markdown("No pipeline execution yet.")
|
| 424 |
|
| 425 |
with gr.Column(scale=4):
|
| 426 |
with gr.Group(elem_classes="dcr-panel"):
|
|
|
|
| 435 |
gr.Markdown(quick_start_md)
|
| 436 |
|
| 437 |
reset_btn.click(
|
| 438 |
+
fn=reset_from_preset,
|
| 439 |
+
inputs=[task_id, scenario_id],
|
| 440 |
+
outputs=[obs_display, raw_json, status, pipeline_runtime, pipeline_steps],
|
| 441 |
)
|
| 442 |
step_btn.click(
|
| 443 |
+
fn=step_with_debug,
|
| 444 |
inputs=[action_type, params_json],
|
| 445 |
+
outputs=[obs_display, raw_json, status, pipeline_runtime, pipeline_steps],
|
| 446 |
)
|
| 447 |
state_btn.click(
|
| 448 |
fn=get_state_sync,
|
| 449 |
+
outputs=[raw_json, pipeline_runtime, pipeline_steps, status],
|
| 450 |
+
)
|
| 451 |
+
task_id.change(
|
| 452 |
+
fn=on_task_change,
|
| 453 |
+
inputs=[task_id],
|
| 454 |
+
outputs=[scenario_id, source_csv, raw_table, final_view, validator_profile],
|
| 455 |
+
)
|
| 456 |
+
scenario_id.change(
|
| 457 |
+
fn=on_scenario_change,
|
| 458 |
+
inputs=[task_id, scenario_id],
|
| 459 |
+
outputs=[source_csv, raw_table, final_view, validator_profile],
|
| 460 |
)
|
| 461 |
|
| 462 |
return demo
|