v2
Browse files
gradio-web/test/test_ui_phase_machine_runtime_e2e.py
CHANGED
|
@@ -1082,52 +1082,39 @@ def test_header_task_switch_to_video_task_shows_demo_phase(monkeypatch):
|
|
| 1082 |
demo_video_path = gr.get_video("world.mp4")
|
| 1083 |
switch_calls = []
|
| 1084 |
|
| 1085 |
-
def
|
| 1086 |
-
_ = request
|
| 1087 |
return (
|
| 1088 |
-
|
| 1089 |
gr.update(visible=True), # main_interface
|
| 1090 |
gr.update(value=fake_obs_img, interactive=False), # img_display
|
| 1091 |
-
"ready", # log_output
|
| 1092 |
gr.update(choices=[("pick", 0)], value=None), # options_radio
|
| 1093 |
-
"goal", # goal_box
|
| 1094 |
"No need for coordinates", # coords_box
|
| 1095 |
-
gr.update(value=None, visible=
|
| 1096 |
-
"
|
| 1097 |
"Completed: 0", # progress_info_box
|
| 1098 |
gr.update(interactive=True), # restart_episode_btn
|
| 1099 |
gr.update(interactive=True), # next_task_btn
|
| 1100 |
gr.update(interactive=True), # exec_btn
|
| 1101 |
-
gr.update(visible=
|
| 1102 |
-
gr.update(visible=
|
| 1103 |
-
gr.update(visible=
|
| 1104 |
-
gr.update(value="hint"), # task_hint_display
|
| 1105 |
gr.update(visible=False), # loading_overlay
|
| 1106 |
gr.update(interactive=True), # reference_action_btn
|
| 1107 |
)
|
| 1108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1109 |
def fake_switch_env_wrapper(uid, selected_env):
|
| 1110 |
switch_calls.append((uid, selected_env))
|
| 1111 |
-
return (
|
| 1112 |
uid,
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
"demo prompt", # log_output
|
| 1116 |
-
gr.update(choices=[("pick", 0)], value=None), # options_radio
|
| 1117 |
-
"video goal", # goal_box
|
| 1118 |
-
"No need for coordinates", # coords_box
|
| 1119 |
-
gr.update(value=demo_video_path, visible=True), # video_display
|
| 1120 |
-
"VideoPlaceButton (Episode 1)", # task_info_box
|
| 1121 |
-
"Completed: 0", # progress_info_box
|
| 1122 |
-
gr.update(interactive=True), # restart_episode_btn
|
| 1123 |
-
gr.update(interactive=True), # next_task_btn
|
| 1124 |
-
gr.update(interactive=True), # exec_btn
|
| 1125 |
-
gr.update(visible=True), # video_phase_group
|
| 1126 |
-
gr.update(visible=False), # action_phase_group
|
| 1127 |
-
gr.update(visible=False), # control_panel_group
|
| 1128 |
-
gr.update(value="video hint"), # task_hint_display
|
| 1129 |
-
gr.update(visible=False), # loading_overlay
|
| 1130 |
-
gr.update(interactive=True), # reference_action_btn
|
| 1131 |
)
|
| 1132 |
|
| 1133 |
monkeypatch.setattr(ui_layout, "init_app", fake_init_app)
|
|
@@ -1163,6 +1150,7 @@ def test_header_task_switch_to_video_task_shows_demo_phase(monkeypatch):
|
|
| 1163 |
}""",
|
| 1164 |
timeout=5000,
|
| 1165 |
)
|
|
|
|
| 1166 |
|
| 1167 |
page.click("#header_task input")
|
| 1168 |
page.get_by_role("option", name="VideoPlaceButton").click()
|
|
@@ -1195,6 +1183,10 @@ def test_header_task_switch_to_video_task_shows_demo_phase(monkeypatch):
|
|
| 1195 |
assert phase_after_switch["currentSrc"]
|
| 1196 |
assert switch_calls == [("uid-header-video", "VideoPlaceButton")]
|
| 1197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1198 |
did_dispatch_end = page.evaluate(
|
| 1199 |
"""() => {
|
| 1200 |
const videoEl = document.querySelector('#demo_video video');
|
|
|
|
| 1082 |
demo_video_path = gr.get_video("world.mp4")
|
| 1083 |
switch_calls = []
|
| 1084 |
|
| 1085 |
+
def _pick_task_response(uid, task_name, show_video):
|
|
|
|
| 1086 |
return (
|
| 1087 |
+
uid,
|
| 1088 |
gr.update(visible=True), # main_interface
|
| 1089 |
gr.update(value=fake_obs_img, interactive=False), # img_display
|
| 1090 |
+
"demo prompt" if show_video else "ready", # log_output
|
| 1091 |
gr.update(choices=[("pick", 0)], value=None), # options_radio
|
| 1092 |
+
"video goal" if show_video else "goal", # goal_box
|
| 1093 |
"No need for coordinates", # coords_box
|
| 1094 |
+
gr.update(value=demo_video_path if show_video else None, visible=show_video), # video_display
|
| 1095 |
+
f"{task_name} (Episode 1)", # task_info_box
|
| 1096 |
"Completed: 0", # progress_info_box
|
| 1097 |
gr.update(interactive=True), # restart_episode_btn
|
| 1098 |
gr.update(interactive=True), # next_task_btn
|
| 1099 |
gr.update(interactive=True), # exec_btn
|
| 1100 |
+
gr.update(visible=show_video), # video_phase_group
|
| 1101 |
+
gr.update(visible=not show_video), # action_phase_group
|
| 1102 |
+
gr.update(visible=not show_video), # control_panel_group
|
| 1103 |
+
gr.update(value="video hint" if show_video else "hint"), # task_hint_display
|
| 1104 |
gr.update(visible=False), # loading_overlay
|
| 1105 |
gr.update(interactive=True), # reference_action_btn
|
| 1106 |
)
|
| 1107 |
|
| 1108 |
+
def fake_init_app(request=None):
|
| 1109 |
+
_ = request
|
| 1110 |
+
return _pick_task_response("uid-header-video", "PickXtimes", show_video=False)
|
| 1111 |
+
|
| 1112 |
def fake_switch_env_wrapper(uid, selected_env):
|
| 1113 |
switch_calls.append((uid, selected_env))
|
| 1114 |
+
return _pick_task_response(
|
| 1115 |
uid,
|
| 1116 |
+
selected_env,
|
| 1117 |
+
show_video=selected_env == "VideoPlaceButton",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1118 |
)
|
| 1119 |
|
| 1120 |
monkeypatch.setattr(ui_layout, "init_app", fake_init_app)
|
|
|
|
| 1150 |
}""",
|
| 1151 |
timeout=5000,
|
| 1152 |
)
|
| 1153 |
+
assert switch_calls == []
|
| 1154 |
|
| 1155 |
page.click("#header_task input")
|
| 1156 |
page.get_by_role("option", name="VideoPlaceButton").click()
|
|
|
|
| 1183 |
assert phase_after_switch["currentSrc"]
|
| 1184 |
assert switch_calls == [("uid-header-video", "VideoPlaceButton")]
|
| 1185 |
|
| 1186 |
+
page.wait_for_timeout(1500)
|
| 1187 |
+
assert switch_calls == [("uid-header-video", "VideoPlaceButton")]
|
| 1188 |
+
assert _read_header_task_value(page) == "VideoPlaceButton"
|
| 1189 |
+
|
| 1190 |
did_dispatch_end = page.evaluate(
|
| 1191 |
"""() => {
|
| 1192 |
const videoEl = document.querySelector('#demo_video video');
|
gradio-web/ui_layout.py
CHANGED
|
@@ -361,8 +361,7 @@ def create_ui_blocks():
|
|
| 361 |
|
| 362 |
uid_state = gr.State(value=None)
|
| 363 |
ui_phase_state = gr.State(value=PHASE_INIT)
|
| 364 |
-
|
| 365 |
-
programmatic_header_task_state = gr.State(value=None)
|
| 366 |
live_obs_timer = gr.Timer(value=1.0 / LIVE_OBS_REFRESH_HZ, active=True)
|
| 367 |
|
| 368 |
task_info_box = gr.Textbox(visible=False, elem_id="task_info_box")
|
|
@@ -557,42 +556,52 @@ def create_ui_blocks():
|
|
| 557 |
def switch_env_with_phase(uid, selected_env):
|
| 558 |
return _with_phase_from_load(switch_env_wrapper(uid, selected_env))
|
| 559 |
|
| 560 |
-
def
|
| 561 |
-
if not selected_env:
|
| 562 |
-
return _skip_load_flow()
|
| 563 |
-
return switch_env_with_phase(uid, selected_env)
|
| 564 |
-
|
| 565 |
-
def prepare_header_task_switch(selected_env, programmatic_selected_env):
|
| 566 |
base_choices = list(user_manager.env_choices)
|
| 567 |
normalized_selected_env = _normalize_env_choice(selected_env, base_choices)
|
| 568 |
-
|
|
|
|
| 569 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
if not normalized_selected_env:
|
| 571 |
-
return
|
| 572 |
-
if normalized_selected_env ==
|
| 573 |
-
return
|
| 574 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
|
| 576 |
task_info_box.change(
|
| 577 |
fn=sync_header_from_task,
|
| 578 |
inputs=[task_info_box, goal_box],
|
| 579 |
-
outputs=[header_task_box, header_goal_box,
|
| 580 |
)
|
| 581 |
goal_box.change(
|
| 582 |
fn=sync_header_from_goal,
|
| 583 |
inputs=[goal_box, task_info_box, header_task_box],
|
| 584 |
-
outputs=[header_task_box, header_goal_box,
|
| 585 |
)
|
| 586 |
|
| 587 |
-
header_task_box.
|
| 588 |
fn=prepare_header_task_switch,
|
| 589 |
-
inputs=[header_task_box,
|
| 590 |
-
outputs=[
|
| 591 |
queue=False,
|
| 592 |
show_progress="hidden",
|
| 593 |
).then(
|
| 594 |
fn=maybe_switch_env_with_phase,
|
| 595 |
-
inputs=[uid_state,
|
| 596 |
outputs=load_flow_outputs,
|
| 597 |
).then(
|
| 598 |
fn=_phase_visibility_updates,
|
|
@@ -601,11 +610,9 @@ def create_ui_blocks():
|
|
| 601 |
queue=False,
|
| 602 |
show_progress="hidden",
|
| 603 |
).then(
|
| 604 |
-
fn=
|
| 605 |
-
inputs=[
|
| 606 |
-
outputs=[
|
| 607 |
-
queue=False,
|
| 608 |
-
show_progress="hidden",
|
| 609 |
)
|
| 610 |
|
| 611 |
next_task_btn.click(fn=show_loading_info, outputs=[loading_overlay]).then(
|
|
@@ -621,7 +628,7 @@ def create_ui_blocks():
|
|
| 621 |
).then(
|
| 622 |
fn=sync_header_from_task,
|
| 623 |
inputs=[task_info_box, goal_box],
|
| 624 |
-
outputs=[header_task_box, header_goal_box,
|
| 625 |
)
|
| 626 |
|
| 627 |
restart_episode_btn.click(fn=show_loading_info, outputs=[loading_overlay]).then(
|
|
@@ -637,7 +644,7 @@ def create_ui_blocks():
|
|
| 637 |
).then(
|
| 638 |
fn=sync_header_from_task,
|
| 639 |
inputs=[task_info_box, goal_box],
|
| 640 |
-
outputs=[header_task_box, header_goal_box,
|
| 641 |
)
|
| 642 |
|
| 643 |
video_display.end(
|
|
@@ -754,7 +761,7 @@ def create_ui_blocks():
|
|
| 754 |
).then(
|
| 755 |
fn=sync_header_from_task,
|
| 756 |
inputs=[task_info_box, goal_box],
|
| 757 |
-
outputs=[header_task_box, header_goal_box,
|
| 758 |
)
|
| 759 |
|
| 760 |
return demo
|
|
|
|
| 361 |
|
| 362 |
uid_state = gr.State(value=None)
|
| 363 |
ui_phase_state = gr.State(value=PHASE_INIT)
|
| 364 |
+
current_task_env_state = gr.State(value=None)
|
|
|
|
| 365 |
live_obs_timer = gr.Timer(value=1.0 / LIVE_OBS_REFRESH_HZ, active=True)
|
| 366 |
|
| 367 |
task_info_box = gr.Textbox(visible=False, elem_id="task_info_box")
|
|
|
|
| 556 |
def switch_env_with_phase(uid, selected_env):
|
| 557 |
return _with_phase_from_load(switch_env_wrapper(uid, selected_env))
|
| 558 |
|
| 559 |
+
def _normalize_selected_env(selected_env, current_task_env):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
base_choices = list(user_manager.env_choices)
|
| 561 |
normalized_selected_env = _normalize_env_choice(selected_env, base_choices)
|
| 562 |
+
normalized_current_env = _normalize_env_choice(current_task_env, base_choices)
|
| 563 |
+
return normalized_selected_env, normalized_current_env
|
| 564 |
|
| 565 |
+
def prepare_header_task_switch(selected_env, current_task_env):
|
| 566 |
+
normalized_selected_env, normalized_current_env = _normalize_selected_env(
|
| 567 |
+
selected_env,
|
| 568 |
+
current_task_env,
|
| 569 |
+
)
|
| 570 |
if not normalized_selected_env:
|
| 571 |
+
return gr.update(visible=False)
|
| 572 |
+
if normalized_selected_env == normalized_current_env:
|
| 573 |
+
return gr.update(visible=False)
|
| 574 |
+
return show_loading_info()
|
| 575 |
+
|
| 576 |
+
def maybe_switch_env_with_phase(uid, selected_env, current_task_env):
|
| 577 |
+
normalized_selected_env, normalized_current_env = _normalize_selected_env(
|
| 578 |
+
selected_env,
|
| 579 |
+
current_task_env,
|
| 580 |
+
)
|
| 581 |
+
if not normalized_selected_env or normalized_selected_env == normalized_current_env:
|
| 582 |
+
return _skip_load_flow()
|
| 583 |
+
return switch_env_with_phase(uid, normalized_selected_env)
|
| 584 |
|
| 585 |
task_info_box.change(
|
| 586 |
fn=sync_header_from_task,
|
| 587 |
inputs=[task_info_box, goal_box],
|
| 588 |
+
outputs=[header_task_box, header_goal_box, current_task_env_state],
|
| 589 |
)
|
| 590 |
goal_box.change(
|
| 591 |
fn=sync_header_from_goal,
|
| 592 |
inputs=[goal_box, task_info_box, header_task_box],
|
| 593 |
+
outputs=[header_task_box, header_goal_box, current_task_env_state],
|
| 594 |
)
|
| 595 |
|
| 596 |
+
header_task_box.select(
|
| 597 |
fn=prepare_header_task_switch,
|
| 598 |
+
inputs=[header_task_box, current_task_env_state],
|
| 599 |
+
outputs=[loading_overlay],
|
| 600 |
queue=False,
|
| 601 |
show_progress="hidden",
|
| 602 |
).then(
|
| 603 |
fn=maybe_switch_env_with_phase,
|
| 604 |
+
inputs=[uid_state, header_task_box, current_task_env_state],
|
| 605 |
outputs=load_flow_outputs,
|
| 606 |
).then(
|
| 607 |
fn=_phase_visibility_updates,
|
|
|
|
| 610 |
queue=False,
|
| 611 |
show_progress="hidden",
|
| 612 |
).then(
|
| 613 |
+
fn=sync_header_from_task,
|
| 614 |
+
inputs=[task_info_box, goal_box],
|
| 615 |
+
outputs=[header_task_box, header_goal_box, current_task_env_state],
|
|
|
|
|
|
|
| 616 |
)
|
| 617 |
|
| 618 |
next_task_btn.click(fn=show_loading_info, outputs=[loading_overlay]).then(
|
|
|
|
| 628 |
).then(
|
| 629 |
fn=sync_header_from_task,
|
| 630 |
inputs=[task_info_box, goal_box],
|
| 631 |
+
outputs=[header_task_box, header_goal_box, current_task_env_state],
|
| 632 |
)
|
| 633 |
|
| 634 |
restart_episode_btn.click(fn=show_loading_info, outputs=[loading_overlay]).then(
|
|
|
|
| 644 |
).then(
|
| 645 |
fn=sync_header_from_task,
|
| 646 |
inputs=[task_info_box, goal_box],
|
| 647 |
+
outputs=[header_task_box, header_goal_box, current_task_env_state],
|
| 648 |
)
|
| 649 |
|
| 650 |
video_display.end(
|
|
|
|
| 761 |
).then(
|
| 762 |
fn=sync_header_from_task,
|
| 763 |
inputs=[task_info_box, goal_box],
|
| 764 |
+
outputs=[header_task_box, header_goal_box, current_task_env_state],
|
| 765 |
)
|
| 766 |
|
| 767 |
return demo
|