Spaces:
Sleeping
Sleeping
shruti.varghese@sandisk.com commited on
Commit ·
85ce402
1
Parent(s): b617763
Fix dropdown update wiring in custom Gradio UI
Browse files- server/ui.py +24 -11
server/ui.py
CHANGED
|
@@ -102,6 +102,19 @@ def _format_runtime_debug(observation: dict[str, Any]) -> tuple[str, str]:
|
|
| 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]],
|
|
@@ -290,23 +303,23 @@ def build_developer_control_room_ui(
|
|
| 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 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 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 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
)
|
| 311 |
|
| 312 |
async def reset_from_preset(task_id: str, scenario_id: 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 "")
|
| 108 |
+
if normalized_value and normalized_value not in normalized_choices:
|
| 109 |
+
normalized_choices = [normalized_value, *normalized_choices]
|
| 110 |
+
if not normalized_choices:
|
| 111 |
+
normalized_choices = [""]
|
| 112 |
+
normalized_value = ""
|
| 113 |
+
elif not normalized_value:
|
| 114 |
+
normalized_value = normalized_choices[0]
|
| 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]],
|
|
|
|
| 303 |
scenario_ids = _scenario_ids_for_task(task_id)
|
| 304 |
scenario_value = scenario_ids[0] if scenario_ids else ""
|
| 305 |
fields = _simulation_fields_for(task_id, scenario_value)
|
| 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):
|