Nathyboy commited on
Commit
719399b
·
verified ·
1 Parent(s): 8c037b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -105,25 +105,25 @@ def fetch_models():
105
  # -----------------------------
106
  def start_webui():
107
  """
108
- 1) Ensure folders exist
109
- 2) Fetch runtime models (only if missing)
110
- 3) Start Automatic1111's launch.py in the same foreground process context
111
- using a subprocess call built from a proper arg list.
 
112
  """
113
  try:
114
  ensure_persistent_folders()
115
-
116
- # Download models (non-blocking safety: we do this before launch so they are present)
117
  fetch_models()
118
 
119
- # Build the command safely
120
- args = ["python", LAUNCH_PY] + shlex.split(WEBUI_ARGS)
121
- print("▶️ Launching WebUI with:", " ".join(args))
 
 
122
 
123
- # Run launch.py and block this thread until it exits; logs go to HF logs.
124
- # We run in a separate Python thread (caller keeps main process alive via Gradio).
125
- subprocess.run(args, check=True)
126
- print("ℹ️ launch.py exited (subprocess finished). If this happens early, check errors above.")
127
  except subprocess.CalledProcessError as cpe:
128
  print(f"❌ launch.py exited with non-zero status: {cpe.returncode}")
129
  except Exception as e:
 
105
  # -----------------------------
106
  def start_webui():
107
  """
108
+ Option B — background WebUI launcher aware of HF tree and persistent folders.
109
+ 1) Ensure persistent folders exist.
110
+ 2) Download missing runtime models.
111
+ 3) Launch Automatic1111 WebUI (launch.py) with correct PORT binding.
112
+ 4) Threaded so Gradio UI stays alive.
113
  """
114
  try:
115
  ensure_persistent_folders()
 
 
116
  fetch_models()
117
 
118
+ # Respect HF Space assigned PORT
119
+ port = int(os.environ.get("PORT", 7860))
120
+ # Build safe command list
121
+ cmd = ["python", LAUNCH_PY] + shlex.split(WEBUI_ARGS) + [f"--port {port}"]
122
+ print("▶️ Launching WebUI with:", " ".join(cmd))
123
 
124
+ # Run launch.py in the current environment, blocking this thread
125
+ subprocess.run(cmd, check=True)
126
+ print("ℹ️ launch.py exited normally.")
 
127
  except subprocess.CalledProcessError as cpe:
128
  print(f"❌ launch.py exited with non-zero status: {cpe.returncode}")
129
  except Exception as e: