rydlrKE commited on
Commit
f4ef391
·
1 Parent(s): c8e8829

Space: auto-retry native proxy load and add direct Qwen example button

Browse files
Files changed (2) hide show
  1. app.py +32 -1
  2. kimodo/demo/ui.py +25 -0
app.py CHANGED
@@ -75,8 +75,39 @@ def _viewer_html() -> str:
75
  src = f"/proxy/{NATIVE_PORT}/"
76
  return (
77
  "<div style='border:1px solid #d9e7ef;border-radius:12px;overflow:hidden;'>"
78
- f"<iframe src='{src}' title='Kimodo UI' style='width:100%;border:0' "
 
 
 
 
79
  "height='920' loading='lazy'></iframe>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  "</div>"
81
  )
82
 
 
75
  src = f"/proxy/{NATIVE_PORT}/"
76
  return (
77
  "<div style='border:1px solid #d9e7ef;border-radius:12px;overflow:hidden;'>"
78
+ "<div id='kimodo-proxy-status' style='padding:8px 12px;font-size:12px;color:#37566b;"
79
+ "background:#f4f9fc;border-bottom:1px solid #d9e7ef;'>"
80
+ "Waiting for native UI to become ready..."
81
+ "</div>"
82
+ f"<iframe id='kimodo-proxy-iframe' src='{src}' title='Kimodo UI' style='width:100%;border:0' "
83
  "height='920' loading='lazy'></iframe>"
84
+ "<script>"
85
+ "(function(){"
86
+ f"const base='/proxy/{NATIVE_PORT}/';"
87
+ "const frame=document.getElementById('kimodo-proxy-iframe');"
88
+ "const status=document.getElementById('kimodo-proxy-status');"
89
+ "let attached=false;"
90
+ "async function tryAttach(){"
91
+ "if(attached){return;}"
92
+ "try{"
93
+ "const res=await fetch(base,{method:'GET',cache:'no-store'});"
94
+ "if(res.ok){"
95
+ "attached=true;"
96
+ "status.textContent='Native UI ready';"
97
+ "frame.src=base+'?t='+Date.now();"
98
+ "setTimeout(function(){status.style.display='none';}, 1500);"
99
+ "return;"
100
+ "}"
101
+ "status.textContent='Starting native UI...';"
102
+ "}catch(e){"
103
+ "status.textContent='Starting native UI...';"
104
+ "}"
105
+ "}"
106
+ "tryAttach();"
107
+ "const timer=setInterval(tryAttach,3000);"
108
+ "setTimeout(function(){clearInterval(timer);},120000);"
109
+ "})();"
110
+ "</script>"
111
  "</div>"
112
  )
113
 
kimodo/demo/ui.py CHANGED
@@ -290,6 +290,9 @@ def create_gui(
290
  example_dict = viser_utils.load_example_cases(examples_base_dir)
291
  example_names = list(example_dict.keys())
292
  example_names.append(QWEN_EXAMPLE_NAME)
 
 
 
293
  print(
294
  "[kimodo][examples][init]"
295
  f" client={client_id} model={model_name} base={examples_base_dir}"
@@ -306,6 +309,12 @@ def create_gui(
306
  hint="Load the selected example (or Qwen agentic prompt plan).",
307
  disabled=False,
308
  )
 
 
 
 
 
 
309
 
310
  def update_examples_dropdown(
311
  new_example_dict: dict[str, str],
@@ -322,6 +331,10 @@ def create_gui(
322
  if QWEN_EXAMPLE_LEGACY_NAME not in example_names_local:
323
  example_names_local.append(QWEN_EXAMPLE_LEGACY_NAME)
324
  gui_examples_dropdown.options = example_names_local
 
 
 
 
325
  print(
326
  "[kimodo][examples][update][exit]"
327
  f" client={client_id} model={model_name} count={len(example_names_local)}"
@@ -2324,6 +2337,18 @@ def create_gui(
2324
  )
2325
  load_example_from_path(event_client, example_path, gui_load_gt_checkbox.value)
2326
 
 
 
 
 
 
 
 
 
 
 
 
 
2327
  @gui_load_example_from_path_button.on_click
2328
  def _(event: viser.GuiEvent) -> None:
2329
  event_client = event.client
 
290
  example_dict = viser_utils.load_example_cases(examples_base_dir)
291
  example_names = list(example_dict.keys())
292
  example_names.append(QWEN_EXAMPLE_NAME)
293
+ gui_examples_debug = client.gui.add_markdown(
294
+ content=f"Examples loaded: {len(example_names)} | Has 09: {QWEN_EXAMPLE_NAME in example_names}"
295
+ )
296
  print(
297
  "[kimodo][examples][init]"
298
  f" client={client_id} model={model_name} base={examples_base_dir}"
 
309
  hint="Load the selected example (or Qwen agentic prompt plan).",
310
  disabled=False,
311
  )
312
+ gui_load_qwen_example_button = client.gui.add_button(
313
+ "Load Qwen Example (09)",
314
+ hint="Directly load the Qwen agentic example plan, bypassing dropdown selection.",
315
+ disabled=False,
316
+ color="blue",
317
+ )
318
 
319
  def update_examples_dropdown(
320
  new_example_dict: dict[str, str],
 
331
  if QWEN_EXAMPLE_LEGACY_NAME not in example_names_local:
332
  example_names_local.append(QWEN_EXAMPLE_LEGACY_NAME)
333
  gui_examples_dropdown.options = example_names_local
334
+ gui_examples_debug.content = (
335
+ f"Examples loaded: {len(example_names_local)} | "
336
+ f"Has 09: {QWEN_EXAMPLE_NAME in example_names_local}"
337
+ )
338
  print(
339
  "[kimodo][examples][update][exit]"
340
  f" client={client_id} model={model_name} count={len(example_names_local)}"
 
2337
  )
2338
  load_example_from_path(event_client, example_path, gui_load_gt_checkbox.value)
2339
 
2340
+ @gui_load_qwen_example_button.on_click
2341
+ def _(event: viser.GuiEvent) -> None:
2342
+ event_client = event.client
2343
+ session = get_active_session(event_client)
2344
+ if session is None:
2345
+ return
2346
+ print(
2347
+ "[kimodo][examples][load_qwen_button]"
2348
+ f" client={client_id} selected={QWEN_EXAMPLE_NAME}"
2349
+ )
2350
+ load_qwen_example_plan(event_client)
2351
+
2352
  @gui_load_example_from_path_button.on_click
2353
  def _(event: viser.GuiEvent) -> None:
2354
  event_client = event.client