Steve Nguyen commited on
Commit
9b9e322
·
1 Parent(s): b826351

debug app

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -384,6 +384,7 @@ def handle_choice(story_state: dict, choice_index: int) -> tuple[dict, str, str,
384
 
385
  def handle_input(story_state: dict, user_input: str) -> tuple[dict, str, str, str, str, dict, str, dict, str, dict, str, dict, dict, str, dict, dict, dict, dict]:
386
  """Store user input and advance to next scene."""
 
387
  scenes: List[SceneState] = story_state["scenes"]
388
  variables = story_state.get("variables", {})
389
  current_scene = scenes[story_state["index"]]
@@ -391,9 +392,11 @@ def handle_input(story_state: dict, user_input: str) -> tuple[dict, str, str, st
391
  if current_scene.input_request and user_input:
392
  variables[current_scene.input_request.variable_name] = user_input
393
  story_state["variables"] = variables
 
394
 
395
  # Advance to next scene
396
  story_state["index"] = min(story_state["index"] + 1, len(scenes) - 1)
 
397
 
398
  html, dialogue, meta, show_camera, show_voice, show_motors, show_robot, choices, input_req = render_scene(
399
  scenes[story_state["index"]], story_state["index"], len(scenes), variables
@@ -402,6 +405,8 @@ def handle_input(story_state: dict, user_input: str) -> tuple[dict, str, str, st
402
  nav_enabled = not bool(choices) and not bool(input_req)
403
  right_column_visible = show_camera or show_voice or show_motors or show_robot
404
 
 
 
405
  return (
406
  story_state,
407
  html,
@@ -425,12 +430,15 @@ def handle_input(story_state: dict, user_input: str) -> tuple[dict, str, str, st
425
 
426
 
427
  def load_initial_state() -> tuple[dict, str, str, str, str, dict, str, dict, str, dict, str, dict, dict, str, dict, dict, dict, dict]:
 
428
  scenes = build_sample_story()
429
  story_state = {"scenes": scenes, "index": 0, "variables": {}, "active_paths": set()}
430
  if scenes:
431
  html, dialogue, meta, show_camera, show_voice, show_motors, show_robot, choices, input_req = render_scene(
432
  scenes[0], 0, len(scenes), {}
433
  )
 
 
434
  else:
435
  html, dialogue, meta, show_camera, show_voice, show_motors, show_robot, choices, input_req = (
436
  "",
@@ -447,6 +455,8 @@ def load_initial_state() -> tuple[dict, str, str, str, str, dict, str, dict, str
447
  nav_enabled = not bool(choices) and not bool(input_req)
448
  right_column_visible = show_camera or show_voice or show_motors or show_robot
449
 
 
 
450
  return (
451
  story_state,
452
  html,
@@ -803,7 +813,14 @@ def play_scene_audio_js() -> str:
803
 
804
  console.log('[Audio] Playing:', audio_path);
805
  audio.src = audio_path;
806
- audio.play().catch(err => console.error('[Audio] Playback failed:', err));
 
 
 
 
 
 
 
807
  }
808
  """
809
 
@@ -1437,6 +1454,9 @@ def main() -> None:
1437
  # Build Gradio app
1438
  demo = build_app()
1439
 
 
 
 
1440
  # Launch with SSR disabled
1441
  demo.launch(
1442
  server_name="0.0.0.0",
 
384
 
385
  def handle_input(story_state: dict, user_input: str) -> tuple[dict, str, str, str, str, dict, str, dict, str, dict, str, dict, dict, str, dict, dict, dict, dict]:
386
  """Store user input and advance to next scene."""
387
+ logger.info(f"Handling input: {user_input}")
388
  scenes: List[SceneState] = story_state["scenes"]
389
  variables = story_state.get("variables", {})
390
  current_scene = scenes[story_state["index"]]
 
392
  if current_scene.input_request and user_input:
393
  variables[current_scene.input_request.variable_name] = user_input
394
  story_state["variables"] = variables
395
+ logger.info(f"Stored variable: {current_scene.input_request.variable_name}={user_input}")
396
 
397
  # Advance to next scene
398
  story_state["index"] = min(story_state["index"] + 1, len(scenes) - 1)
399
+ logger.info(f"Advanced to scene {story_state['index']}")
400
 
401
  html, dialogue, meta, show_camera, show_voice, show_motors, show_robot, choices, input_req = render_scene(
402
  scenes[story_state["index"]], story_state["index"], len(scenes), variables
 
405
  nav_enabled = not bool(choices) and not bool(input_req)
406
  right_column_visible = show_camera or show_voice or show_motors or show_robot
407
 
408
+ logger.info(f"After input: input_req visible={bool(input_req)}, choices visible={bool(choices)}")
409
+
410
  return (
411
  story_state,
412
  html,
 
430
 
431
 
432
  def load_initial_state() -> tuple[dict, str, str, str, str, dict, str, dict, str, dict, str, dict, dict, str, dict, dict, dict, dict]:
433
+ logger.info("Loading initial state...")
434
  scenes = build_sample_story()
435
  story_state = {"scenes": scenes, "index": 0, "variables": {}, "active_paths": set()}
436
  if scenes:
437
  html, dialogue, meta, show_camera, show_voice, show_motors, show_robot, choices, input_req = render_scene(
438
  scenes[0], 0, len(scenes), {}
439
  )
440
+ logger.info(f"Initial scene: choices={choices is not None}, input_req={input_req is not None}")
441
+ logger.info(f"HTML length: {len(html) if html else 0}")
442
  else:
443
  html, dialogue, meta, show_camera, show_voice, show_motors, show_robot, choices, input_req = (
444
  "",
 
455
  nav_enabled = not bool(choices) and not bool(input_req)
456
  right_column_visible = show_camera or show_voice or show_motors or show_robot
457
 
458
+ logger.info(f"Initial state: input_req visible={bool(input_req)}, choices visible={bool(choices)}")
459
+
460
  return (
461
  story_state,
462
  html,
 
813
 
814
  console.log('[Audio] Playing:', audio_path);
815
  audio.src = audio_path;
816
+
817
+ // Try to play with better error handling for HuggingFace Spaces
818
+ audio.play()
819
+ .then(() => console.log('[Audio] Playback started successfully'))
820
+ .catch(err => {
821
+ console.error('[Audio] Playback failed:', err.message);
822
+ console.error('[Audio] Note: Browsers may block autoplay. User interaction may be required.');
823
+ });
824
  }
825
  """
826
 
 
1454
  # Build Gradio app
1455
  demo = build_app()
1456
 
1457
+ # Enable queue for HuggingFace Spaces (required for proper component updates)
1458
+ demo.queue(default_concurrency_limit=10)
1459
+
1460
  # Launch with SSR disabled
1461
  demo.launch(
1462
  server_name="0.0.0.0",