AnimeOverlord commited on
Commit
b40be43
·
1 Parent(s): 3b169dd

new update fix

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -1,8 +1,7 @@
1
  """
2
  Minecraftify! — turn any photo into a Minecraft-style scene.
3
 
4
- Beautiful Minecraft-themed Gradio UI with a dummy inference function
5
- (color inversion) for testing. Swap in the real model later.
6
  """
7
 
8
  import os
@@ -857,7 +856,6 @@ def minecraftify_live_loop(
857
 
858
  if not is_active:
859
  log_event("Live GPU loop stopped")
860
- yield gr.skip(), "Live camera is stopped."
861
  return
862
 
863
  if frame is None:
@@ -871,7 +869,7 @@ def minecraftify_live_loop(
871
  last_processed_frame_id = frame_id
872
  log_event(f"Processing newest live frame id={frame_id}")
873
  output = _minecraftify_image(frame, steps, guidance_scale, seed, extra_details)
874
- yield output, f"Live camera is running. Processed frame {frame_id}."
875
 
876
 
877
  def switch_input_mode(mode: str):
@@ -889,7 +887,6 @@ def switch_input_mode(mode: str):
889
  gr.update(interactive=True),
890
  gr.update(visible=not image_mode, interactive=False),
891
  False,
892
- "Live camera is stopped.",
893
  )
894
 
895
 
@@ -909,7 +906,6 @@ def start_live(image: Image.Image):
909
  True,
910
  gr.update(interactive=False),
911
  gr.update(interactive=True),
912
- "Live camera is running. Minecraft frames will appear on the right.",
913
  )
914
 
915
 
@@ -922,7 +918,6 @@ def stop_live():
922
  False,
923
  gr.update(interactive=True),
924
  gr.update(interactive=False),
925
- "Live camera is stopped.",
926
  )
927
 
928
 
@@ -930,7 +925,14 @@ def stop_live():
930
  # UI
931
  # ----------------------------------------------------------------------
932
 
933
- preload_model_on_startup()
 
 
 
 
 
 
 
934
  log_event("Building Gradio UI")
935
 
936
  with gr.Blocks(**BLOCKS_KWARGS) as demo:
@@ -993,13 +995,6 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
993
  interactive=False,
994
  )
995
 
996
- live_status = gr.Textbox(
997
- label="Live status",
998
- value="Live camera is stopped.",
999
- interactive=False,
1000
- lines=1,
1001
- )
1002
-
1003
  extra_details = gr.Textbox(
1004
  label="🗒️ Extra scene details (optional)",
1005
  placeholder="e.g. 'this is a beach at sunset' or 'make the dog a wolf mob'...",
@@ -1083,7 +1078,6 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1083
  start_live_btn,
1084
  stop_live_btn,
1085
  live_running,
1086
- live_status,
1087
  ],
1088
  queue=False,
1089
  )
@@ -1097,21 +1091,21 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1097
  start_live_event = start_live_btn.click(
1098
  fn=start_live,
1099
  inputs=live_image,
1100
- outputs=[live_running, start_live_btn, stop_live_btn, live_status],
1101
  queue=False,
1102
  )
1103
 
1104
  start_live_event.then(
1105
  fn=minecraftify_live_loop,
1106
  inputs=[steps, guidance_scale, seed, extra_details],
1107
- outputs=[output_image, live_status],
1108
  concurrency_limit=1,
1109
  )
1110
 
1111
  stop_live_btn.click(
1112
  fn=stop_live,
1113
  inputs=None,
1114
- outputs=[live_running, start_live_btn, stop_live_btn, live_status],
1115
  queue=False,
1116
  )
1117
 
 
1
  """
2
  Minecraftify! — turn any photo into a Minecraft-style scene.
3
 
4
+ Gradio UI with FLUX.2 diffusion model + Minecraft LoRA for converting images to Minecraft style.
 
5
  """
6
 
7
  import os
 
856
 
857
  if not is_active:
858
  log_event("Live GPU loop stopped")
 
859
  return
860
 
861
  if frame is None:
 
869
  last_processed_frame_id = frame_id
870
  log_event(f"Processing newest live frame id={frame_id}")
871
  output = _minecraftify_image(frame, steps, guidance_scale, seed, extra_details)
872
+ yield output
873
 
874
 
875
  def switch_input_mode(mode: str):
 
887
  gr.update(interactive=True),
888
  gr.update(visible=not image_mode, interactive=False),
889
  False,
 
890
  )
891
 
892
 
 
906
  True,
907
  gr.update(interactive=False),
908
  gr.update(interactive=True),
 
909
  )
910
 
911
 
 
918
  False,
919
  gr.update(interactive=True),
920
  gr.update(interactive=False),
 
921
  )
922
 
923
 
 
925
  # UI
926
  # ----------------------------------------------------------------------
927
 
928
+ # Start model preload in background thread to avoid blocking UI
929
+ if PRELOAD_MODEL_ON_STARTUP:
930
+ preload_thread = threading.Thread(target=preload_model_on_startup, daemon=True)
931
+ preload_thread.start()
932
+ log_event("Model preload started in background thread")
933
+ else:
934
+ log_event("Startup model preload disabled by PRELOAD_MODEL_ON_STARTUP=0")
935
+
936
  log_event("Building Gradio UI")
937
 
938
  with gr.Blocks(**BLOCKS_KWARGS) as demo:
 
995
  interactive=False,
996
  )
997
 
 
 
 
 
 
 
 
998
  extra_details = gr.Textbox(
999
  label="🗒️ Extra scene details (optional)",
1000
  placeholder="e.g. 'this is a beach at sunset' or 'make the dog a wolf mob'...",
 
1078
  start_live_btn,
1079
  stop_live_btn,
1080
  live_running,
 
1081
  ],
1082
  queue=False,
1083
  )
 
1091
  start_live_event = start_live_btn.click(
1092
  fn=start_live,
1093
  inputs=live_image,
1094
+ outputs=[live_running, start_live_btn, stop_live_btn],
1095
  queue=False,
1096
  )
1097
 
1098
  start_live_event.then(
1099
  fn=minecraftify_live_loop,
1100
  inputs=[steps, guidance_scale, seed, extra_details],
1101
+ outputs=[output_image],
1102
  concurrency_limit=1,
1103
  )
1104
 
1105
  stop_live_btn.click(
1106
  fn=stop_live,
1107
  inputs=None,
1108
+ outputs=[live_running, start_live_btn, stop_live_btn],
1109
  queue=False,
1110
  )
1111