File size: 17,365 Bytes
3dff563 06c11b0 de73880 06c11b0 de73880 3dff563 6b17232 3dff563 de73880 3dff563 06c11b0 3dff563 de73880 3dff563 de73880 3dff563 de73880 3dff563 de73880 3dff563 de73880 3dff563 de73880 3dff563 de73880 3dff563 de73880 3dff563 ac3240e 3dff563 ac3240e 3dff563 06c11b0 3dff563 179063c 3dff563 179063c 3dff563 179063c 3dff563 06c11b0 3dff563 179063c 3dff563 2c68370 3dff563 239de5c 3dff563 2c68370 3dff563 2c68370 3dff563 2c68370 3dff563 179063c 6b17232 de73880 6b17232 179063c 239de5c de73880 06c11b0 6b17232 de73880 06c11b0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | """Dummy Gradio entrypoint with layout similar to original RoboMME UI."""
import logging
import os
import sys
# Disable SSR for HF Spaces compatibility (avoids gradio_api heartbeat 404).
os.environ["GRADIO_SSR_MODE"] = "false"
import gradio as gr
import numpy as np
PHASE_DEMO_VIDEO = "demo_video"
PHASE_ACTION_KEYPOINT = "action_keypoint"
DUMMY_TASKS = [
"Peg Insertion Side",
"Pick Cube and Place",
"Stack Green Block",
"Open Cabinet Door",
]
CSS = """
#loading_overlay_group {
position: fixed !important;
inset: 0 !important;
z-index: 9999 !important;
background: rgba(255, 255, 255, 0.92) !important;
text-align: center !important;
}
#loading_overlay_group > div {
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
"""
def _setup_logging() -> logging.Logger:
"""Configure terminal logging for runtime debugging."""
level_name = os.getenv("LOG_LEVEL", "INFO").upper()
level = getattr(logging, level_name, logging.INFO)
try:
sys.stdout.reconfigure(line_buffering=True)
except Exception:
pass
logging.basicConfig(
level=level,
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
stream=sys.stdout,
force=True,
)
# Keep noisy dependency logs down unless explicitly requested.
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("uvicorn.access").setLevel(logging.INFO)
logger = logging.getLogger("robomme.app")
logger.info("Logging initialized with LOG_LEVEL=%s", level_name)
return logger
LOGGER = _setup_logging()
def _task_goal(task_name: str) -> str:
return f"Dummy goal for {task_name}"
def _task_hint(task_name: str) -> str:
return (
f"[DUMMY] Current task: {task_name}\n"
"1) Select an action option.\n"
"2) Click image when action needs coordinates.\n"
"3) Press EXECUTE to simulate one step."
)
def _task_actions(task_name: str) -> list[str]:
return [
f"{task_name}: Move",
f"{task_name}: Grasp",
f"{task_name}: Place",
"Reset Arm Pose",
]
def _dummy_frame(task_name: str, step: int) -> np.ndarray:
seed = sum(ord(ch) for ch in task_name) + step * 31
r = 80 + (seed % 120)
g = 80 + ((seed * 3) % 120)
b = 80 + ((seed * 7) % 120)
frame = np.zeros((360, 640, 3), dtype=np.uint8)
frame[:, :] = [r, g, b]
frame[20:340, 20:620] = [min(r + 25, 255), min(g + 25, 255), min(b + 25, 255)]
frame[170:190, 40:600] = [245, 245, 245]
return frame
def _build_task_updates(task_name: str, step: int, phase: str) -> tuple:
in_video_phase = phase == PHASE_DEMO_VIDEO
log_text = (
f"[DUMMY] Loaded task: {task_name}\n"
+ ("[DUMMY] Demo video phase. Click 'Skip Demo Video' to continue." if in_video_phase else "[DUMMY] Action phase ready.")
)
return (
_task_goal(task_name),
gr.update(choices=_task_actions(task_name), value=None),
"",
log_text,
_task_hint(task_name),
f"Episode progress: {step}/5 (dummy)",
_dummy_frame(task_name, step),
gr.update(visible=in_video_phase),
gr.update(visible=not in_video_phase),
gr.update(visible=not in_video_phase),
phase,
)
def create_dummy_demo() -> gr.Blocks:
"""Build a dummy app that mimics original layout without ManiSkill."""
def on_task_change(task_name: str):
LOGGER.debug("on_task_change(task_name=%s)", task_name)
task = task_name if task_name in DUMMY_TASKS else DUMMY_TASKS[0]
step = 0
return (step,) + _build_task_updates(task, step, PHASE_DEMO_VIDEO)
def skip_video(task_name: str, step: int):
LOGGER.debug("skip_video(task_name=%s, step=%s)", task_name, step)
task = task_name if task_name in DUMMY_TASKS else DUMMY_TASKS[0]
return _build_task_updates(task, step, PHASE_ACTION_KEYPOINT)
def on_reference_action(task_name: str):
LOGGER.debug("on_reference_action(task_name=%s)", task_name)
actions = _task_actions(task_name)
return (
gr.update(value=actions[0]),
"[DUMMY] Filled with reference action.",
)
def on_map_click(evt: gr.SelectData):
if evt is None or evt.index is None:
LOGGER.debug("on_map_click received empty event")
return ""
x, y = evt.index
LOGGER.debug("on_map_click(x=%s, y=%s)", x, y)
return f"({x}, {y})"
def execute_step(task_name: str, action_name: str, coords_text: str, step: int):
LOGGER.info(
"execute_step(task_name=%s, action=%s, coords=%s, step=%s)",
task_name,
action_name,
coords_text,
step,
)
task = task_name if task_name in DUMMY_TASKS else DUMMY_TASKS[0]
next_step = min(step + 1, 5)
action = action_name or "No action selected"
coords = coords_text.strip() if coords_text else "N/A"
log = (
f"[DUMMY] Execute step {next_step}/5\n"
f"- task: {task}\n"
f"- action: {action}\n"
f"- coords: {coords}"
)
progress = f"Episode progress: {next_step}/5 (dummy)"
return next_step, _dummy_frame(task, next_step), log, progress
def restart_episode(task_name: str):
LOGGER.info("restart_episode(task_name=%s)", task_name)
task = task_name if task_name in DUMMY_TASKS else DUMMY_TASKS[0]
step = 0
return (step,) + _build_task_updates(task, step, PHASE_DEMO_VIDEO)
def next_task(current_task: str):
LOGGER.info("next_task(current_task=%s)", current_task)
try:
idx = DUMMY_TASKS.index(current_task)
except ValueError:
idx = 0
nxt = DUMMY_TASKS[(idx + 1) % len(DUMMY_TASKS)]
step = 0
return (nxt, step) + _build_task_updates(nxt, step, PHASE_DEMO_VIDEO)
with gr.Blocks(title="Oracle Planner Interface") as demo:
demo.theme = gr.themes.Soft()
demo.css = CSS
step_state = gr.State(0)
ui_phase_state = gr.State(PHASE_DEMO_VIDEO)
gr.Markdown("## RoboMME Human Evaluation", elem_id="header_title")
with gr.Row():
with gr.Column(scale=1):
header_task_box = gr.Dropdown(
choices=DUMMY_TASKS,
value=DUMMY_TASKS[0],
label="Current Task",
show_label=True,
interactive=True,
elem_id="header_task",
)
with gr.Column(scale=2):
header_goal_box = gr.Textbox(
value=_task_goal(DUMMY_TASKS[0]),
label="Goal",
show_label=True,
interactive=False,
lines=1,
elem_id="header_goal",
)
with gr.Column(visible=False, elem_id="loading_overlay_group") as loading_overlay:
gr.Markdown("### Logging in and setting up environment... Please wait.")
with gr.Column(visible=True, elem_id="main_interface_root") as main_interface:
with gr.Row(elem_id="main_layout_row"):
with gr.Column(scale=5):
with gr.Column(elem_classes=["native-card"], elem_id="media_card"):
with gr.Column(visible=True, elem_id="video_phase_group") as video_phase_group:
video_display = gr.Video(
label="Demonstration Video",
interactive=False,
elem_id="demo_video",
autoplay=False,
show_label=True,
value=None,
visible=True,
)
skip_video_btn = gr.Button("Skip Demo Video", variant="secondary")
with gr.Column(visible=False, elem_id="action_phase_group") as action_phase_group:
img_display = gr.Image(
label="Keypoint Selection",
interactive=False,
type="numpy",
elem_id="live_obs",
show_label=True,
buttons=[],
sources=[],
value=_dummy_frame(DUMMY_TASKS[0], 0),
)
with gr.Column(scale=4):
with gr.Column(visible=False, elem_id="control_panel_group") as control_panel_group:
with gr.Row(elem_id="right_top_row", equal_height=False):
with gr.Column(scale=3, elem_id="right_action_col"):
with gr.Column(elem_classes=["native-card"], elem_id="action_selection_card"):
options_radio = gr.Radio(
choices=_task_actions(DUMMY_TASKS[0]),
label=" Action Selection",
type="value",
show_label=True,
elem_id="action_radio",
)
coords_box = gr.Textbox(
label="Coords",
value="",
interactive=False,
show_label=False,
visible=False,
elem_id="coords_box",
)
with gr.Column(scale=2, elem_id="right_log_col"):
with gr.Column(elem_classes=["native-card"], elem_id="log_card"):
log_output = gr.Textbox(
value="[DUMMY] Demo video phase. Click 'Skip Demo Video' to continue.",
lines=4,
max_lines=None,
show_label=True,
interactive=False,
elem_id="log_output",
label="System Log",
)
with gr.Row(elem_id="action_buttons_row"):
with gr.Column(elem_classes=["native-card", "native-button-card"], elem_id="exec_btn_card"):
exec_btn = gr.Button("EXECUTE", variant="stop", size="lg", elem_id="exec_btn")
with gr.Column(
elem_classes=["native-card", "native-button-card"],
elem_id="reference_btn_card",
):
reference_action_btn = gr.Button(
"Ground Truth Action",
variant="secondary",
interactive=True,
elem_id="reference_action_btn",
)
with gr.Column(
elem_classes=["native-card", "native-button-card"],
elem_id="restart_episode_btn_card",
):
restart_episode_btn = gr.Button(
"restart episode",
variant="secondary",
interactive=True,
elem_id="restart_episode_btn",
)
with gr.Column(
elem_classes=["native-card", "native-button-card"],
elem_id="next_task_btn_card",
):
next_task_btn = gr.Button(
"change episode",
variant="primary",
interactive=True,
elem_id="next_task_btn",
)
with gr.Accordion(
"Task Hint",
open=False,
visible=True,
elem_classes=["native-card"],
elem_id="task_hint_card",
):
task_hint_display = gr.Textbox(
value=_task_hint(DUMMY_TASKS[0]),
lines=8,
max_lines=16,
show_label=False,
interactive=True,
elem_id="task_hint_display",
)
progress_info_box = gr.Textbox(value="Episode progress: 0/5 (dummy)", visible=False)
header_task_box.change(
fn=on_task_change,
inputs=[header_task_box],
outputs=[
step_state,
header_goal_box,
options_radio,
coords_box,
log_output,
task_hint_display,
progress_info_box,
img_display,
video_phase_group,
action_phase_group,
control_panel_group,
ui_phase_state,
],
)
skip_video_btn.click(
fn=skip_video,
inputs=[header_task_box, step_state],
outputs=[
header_goal_box,
options_radio,
coords_box,
log_output,
task_hint_display,
progress_info_box,
img_display,
video_phase_group,
action_phase_group,
control_panel_group,
ui_phase_state,
],
)
img_display.select(
fn=on_map_click,
outputs=[coords_box],
)
reference_action_btn.click(
fn=on_reference_action,
inputs=[header_task_box],
outputs=[options_radio, log_output],
)
exec_btn.click(
fn=execute_step,
inputs=[header_task_box, options_radio, coords_box, step_state],
outputs=[step_state, img_display, log_output, progress_info_box],
)
restart_episode_btn.click(
fn=restart_episode,
inputs=[header_task_box],
outputs=[
step_state,
header_goal_box,
options_radio,
coords_box,
log_output,
task_hint_display,
progress_info_box,
img_display,
video_phase_group,
action_phase_group,
control_panel_group,
ui_phase_state,
],
)
next_task_btn.click(
fn=next_task,
inputs=[header_task_box],
outputs=[
header_task_box,
step_state,
header_goal_box,
options_radio,
coords_box,
log_output,
task_hint_display,
progress_info_box,
img_display,
video_phase_group,
action_phase_group,
control_panel_group,
ui_phase_state,
],
)
demo.load(
fn=on_task_change,
inputs=[header_task_box],
outputs=[
step_state,
header_goal_box,
options_radio,
coords_box,
log_output,
task_hint_display,
progress_info_box,
img_display,
video_phase_group,
action_phase_group,
control_panel_group,
ui_phase_state,
],
)
return demo
demo = create_dummy_demo()
# Ensure external launch() callers (e.g., Spaces runtime) also keep SSR disabled.
_original_launch = demo.launch
def _patched_launch(**kwargs):
kwargs.setdefault("ssr_mode", False)
kwargs.setdefault("show_error", True)
kwargs.setdefault("debug", True)
kwargs.setdefault("quiet", False)
LOGGER.info("Launching app with kwargs=%s", kwargs)
return _original_launch(**kwargs)
demo.launch = _patched_launch
if __name__ == "__main__":
LOGGER.info("Starting app.py entrypoint")
demo.launch(
server_name="0.0.0.0",
server_port=int(os.getenv("PORT", "7860")),
ssr_mode=False,
show_error=True,
debug=True,
quiet=False,
)
|