AnimeOverlord commited on
Commit
849e2b4
·
1 Parent(s): e94694b

new update fix

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -838,6 +838,7 @@ def minecraftify(
838
  return _minecraftify_image(image, steps, guidance_scale, seed, extra_details)
839
 
840
 
 
841
  def _minecraftify_live_frame(
842
  frame: Image.Image,
843
  steps: int,
@@ -845,8 +846,8 @@ def _minecraftify_live_frame(
845
  seed: int,
846
  extra_details: str,
847
  ):
848
- """Inference for individual live frames (GPU held at loop level)."""
849
- log_event(f"Processing live frame with steps={steps}")
850
  return _minecraftify_image(frame, steps, guidance_scale, seed, extra_details)
851
 
852
 
@@ -869,14 +870,13 @@ def capture_live_frame(image: Image.Image):
869
  return None
870
 
871
 
872
- def _minecraftify_live_loop_gpu(
873
  steps: int,
874
  guidance_scale: float,
875
  seed: int,
876
  extra_details: str,
877
  ):
878
- """GPU-held loop for live processing - holds GPU for 120 seconds."""
879
- log_event("Live GPU loop started (GPU allocated for 120s)")
880
  last_processed_frame_id = 0
881
 
882
  while True:
@@ -903,24 +903,13 @@ def _minecraftify_live_loop_gpu(
903
  yield output
904
 
905
 
906
- @spaces.GPU(duration=120)
907
- def minecraftify_live_loop(
908
- steps: int,
909
- guidance_scale: float,
910
- seed: int,
911
- extra_details: str,
912
- ):
913
- """Wrapper that holds GPU for entire 120-second live stream session."""
914
- yield from _minecraftify_live_loop_gpu(steps, guidance_scale, seed, extra_details)
915
-
916
-
917
  def _set_live_active(image: Image.Image):
918
  """Auto-enable live processing when recording starts."""
919
  global _live_active
920
  if image is not None and not _live_active:
921
  _live_active = True
922
  log_event("Live recording detected, auto-starting processing")
923
- return None
924
 
925
 
926
  def switch_input_mode(mode: str):
@@ -938,6 +927,7 @@ def switch_input_mode(mode: str):
938
  gr.update(interactive=True),
939
  gr.update(visible=not image_mode, interactive=False),
940
  False,
 
941
  )
942
 
943
 
@@ -1082,6 +1072,7 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1082
 
1083
  # ── Event binding ──
1084
  live_running = gr.State(False)
 
1085
 
1086
  input_mode.change(
1087
  fn=switch_input_mode,
@@ -1091,6 +1082,7 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1091
  run_btn,
1092
  live_input_group,
1093
  live_running,
 
1094
  ],
1095
  queue=False,
1096
  )
@@ -1102,13 +1094,15 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1102
  )
1103
 
1104
  live_image.stream(
1105
- fn=lambda img: _set_live_active(img),
1106
  inputs=live_image,
1107
- outputs=None,
1108
  stream_every=0.05,
1109
  trigger_mode="always_last",
1110
  queue=False,
1111
- ).then(
 
 
1112
  fn=minecraftify_live_loop,
1113
  inputs=[steps, guidance_scale, seed, extra_details],
1114
  outputs=[output_image],
 
838
  return _minecraftify_image(image, steps, guidance_scale, seed, extra_details)
839
 
840
 
841
+ @spaces.GPU(duration=120)
842
  def _minecraftify_live_frame(
843
  frame: Image.Image,
844
  steps: int,
 
846
  seed: int,
847
  extra_details: str,
848
  ):
849
+ """GPU-wrapped inference for individual live frames."""
850
+ log_event(f"GPU-allocated: Processing live frame with steps={steps}")
851
  return _minecraftify_image(frame, steps, guidance_scale, seed, extra_details)
852
 
853
 
 
870
  return None
871
 
872
 
873
+ def minecraftify_live_loop(
874
  steps: int,
875
  guidance_scale: float,
876
  seed: int,
877
  extra_details: str,
878
  ):
879
+ log_event("Live GPU loop started")
 
880
  last_processed_frame_id = 0
881
 
882
  while True:
 
903
  yield output
904
 
905
 
 
 
 
 
 
 
 
 
 
 
 
906
  def _set_live_active(image: Image.Image):
907
  """Auto-enable live processing when recording starts."""
908
  global _live_active
909
  if image is not None and not _live_active:
910
  _live_active = True
911
  log_event("Live recording detected, auto-starting processing")
912
+ return gr.update(active=_live_active) # Enable timer when active
913
 
914
 
915
  def switch_input_mode(mode: str):
 
927
  gr.update(interactive=True),
928
  gr.update(visible=not image_mode, interactive=False),
929
  False,
930
+ gr.update(active=not image_mode), # Deactivate timer in image mode
931
  )
932
 
933
 
 
1072
 
1073
  # ── Event binding ──
1074
  live_running = gr.State(False)
1075
+ processing_timer = gr.Timer(interval=0.1, active=False)
1076
 
1077
  input_mode.change(
1078
  fn=switch_input_mode,
 
1082
  run_btn,
1083
  live_input_group,
1084
  live_running,
1085
+ processing_timer,
1086
  ],
1087
  queue=False,
1088
  )
 
1094
  )
1095
 
1096
  live_image.stream(
1097
+ fn=_set_live_active,
1098
  inputs=live_image,
1099
+ outputs=processing_timer,
1100
  stream_every=0.05,
1101
  trigger_mode="always_last",
1102
  queue=False,
1103
+ )
1104
+
1105
+ processing_timer.tick(
1106
  fn=minecraftify_live_loop,
1107
  inputs=[steps, guidance_scale, seed, extra_details],
1108
  outputs=[output_image],