HongzeFu commited on
Commit
cdaf10a
·
1 Parent(s): ac3240e

fix task dropdown select bug

Browse files
gradio-web/gradio_callbacks.py CHANGED
@@ -76,7 +76,10 @@ def _entry_rejected_text():
76
 
77
  def touch_session(uid):
78
  """Re-emit the current session key to refresh gr.State TTL."""
79
- return uid if uid and get_session(uid) is not None else None
 
 
 
80
 
81
 
82
  def cleanup_user_session(uid):
@@ -278,10 +281,16 @@ def on_video_end(uid):
278
 
279
  def on_demo_video_play(uid):
280
  """Mark the demo video as consumed and disable the play button."""
281
- if not get_session(uid):
282
- LOGGER.warning("on_demo_video_play: missing session uid=%s", _uid_for_log(uid))
283
  raise gr.Error(_session_error_text())
284
 
 
 
 
 
 
 
285
  already_clicked = get_play_button_clicked(uid)
286
  if not already_clicked:
287
  set_play_button_clicked(uid, True)
 
76
 
77
  def touch_session(uid):
78
  """Re-emit the current session key to refresh gr.State TTL."""
79
+ if not uid:
80
+ return None
81
+ # Keep the browser-side uid even when the backend session is stubbed or not yet materialized.
82
+ return uid
83
 
84
 
85
  def cleanup_user_session(uid):
 
281
 
282
  def on_demo_video_play(uid):
283
  """Mark the demo video as consumed and disable the play button."""
284
+ if not uid:
285
+ LOGGER.warning("on_demo_video_play: missing uid")
286
  raise gr.Error(_session_error_text())
287
 
288
+ if not get_session(uid):
289
+ LOGGER.warning(
290
+ "on_demo_video_play: missing session uid=%s; disabling button anyway",
291
+ _uid_for_log(uid),
292
+ )
293
+
294
  already_clicked = get_play_button_clicked(uid)
295
  if not already_clicked:
296
  set_play_button_clicked(uid, True)
gradio-web/ui_layout.py CHANGED
@@ -342,9 +342,9 @@ SET_EPISODE_LOAD_MODE_JS = f"""
342
  }}
343
  """
344
 
345
-
346
  SET_EPISODE_LOAD_MODE_IF_SWITCH_JS = f"""
347
- (_uid, selectedEnv, currentTaskEnv) => {{
348
  const normalize = (value) => (value == null ? "" : String(value).trim().toLowerCase());
349
  const nextEnv = normalize(selectedEnv);
350
  const currentEnv = normalize(currentTaskEnv);
@@ -352,6 +352,7 @@ SET_EPISODE_LOAD_MODE_IF_SWITCH_JS = f"""
352
  nextEnv && nextEnv !== currentEnv
353
  ? {json.dumps(LOAD_STATUS_MODE_EPISODE_LOAD)}
354
  : {json.dumps(LOAD_STATUS_MODE_IDLE)};
 
355
  }}
356
  """
357
 
 
342
  }}
343
  """
344
 
345
+ # Gradio js preprocessors with inputs must return the original args, or Python receives None.
346
  SET_EPISODE_LOAD_MODE_IF_SWITCH_JS = f"""
347
+ (uid, selectedEnv, currentTaskEnv) => {{
348
  const normalize = (value) => (value == null ? "" : String(value).trim().toLowerCase());
349
  const nextEnv = normalize(selectedEnv);
350
  const currentEnv = normalize(currentTaskEnv);
 
352
  nextEnv && nextEnv !== currentEnv
353
  ? {json.dumps(LOAD_STATUS_MODE_EPISODE_LOAD)}
354
  : {json.dumps(LOAD_STATUS_MODE_IDLE)};
355
+ return [uid, selectedEnv, currentTaskEnv];
356
  }}
357
  """
358