Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -105,25 +105,25 @@ def fetch_models():
|
|
| 105 |
# -----------------------------
|
| 106 |
def start_webui():
|
| 107 |
"""
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
| 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 |
-
#
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
# Run launch.py
|
| 124 |
-
|
| 125 |
-
|
| 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:
|