Spaces:
Running on Zero
Running on Zero
fix: HTTP readiness gate in _ensure_text_encoder_server
Browse files- kimodo/model/load_model.py +19 -2
kimodo/model/load_model.py
CHANGED
|
@@ -67,6 +67,17 @@ def _is_port_open(text_encoder_url: str, timeout_sec: float = 1.0) -> bool:
|
|
| 67 |
return False
|
| 68 |
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def _build_text_encoder_env() -> dict[str, str]:
|
| 71 |
env = os.environ.copy()
|
| 72 |
token = (
|
|
@@ -104,8 +115,14 @@ def _ensure_text_encoder_server(text_encoder_url: str) -> None:
|
|
| 104 |
deadline = time.time() + startup_timeout_sec
|
| 105 |
while time.time() < deadline:
|
| 106 |
if _is_port_open(text_encoder_url):
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
if _TEXT_ENCODER_SERVER_PROCESS.poll() is not None:
|
| 110 |
raise RuntimeError(
|
| 111 |
"Text encoder server process exited during startup. "
|
|
|
|
| 67 |
return False
|
| 68 |
|
| 69 |
|
| 70 |
+
def _is_http_ready(text_encoder_url: str, timeout_sec: float = 3.0) -> bool:
|
| 71 |
+
"""Return True when the Gradio server at *text_encoder_url* responds to HTTP (serves /info)."""
|
| 72 |
+
try:
|
| 73 |
+
import urllib.request
|
| 74 |
+
|
| 75 |
+
info_url = text_encoder_url.rstrip("/") + "/info"
|
| 76 |
+
req = urllib.request.urlopen(info_url, timeout=timeout_sec) # noqa: S310
|
| 77 |
+
return req.status == 200
|
| 78 |
+
except Exception:
|
| 79 |
+
return False
|
| 80 |
+
|
| 81 |
def _build_text_encoder_env() -> dict[str, str]:
|
| 82 |
env = os.environ.copy()
|
| 83 |
token = (
|
|
|
|
| 115 |
deadline = time.time() + startup_timeout_sec
|
| 116 |
while time.time() < deadline:
|
| 117 |
if _is_port_open(text_encoder_url):
|
| 118 |
+
# Port is open — wait for HTTP layer to be ready (Gradio SSR init can lag)
|
| 119 |
+
http_deadline = min(time.time() + 30, deadline)
|
| 120 |
+
while time.time() < http_deadline:
|
| 121 |
+
if _is_http_ready(text_encoder_url):
|
| 122 |
+
print("Text encoder server is HTTP-ready.")
|
| 123 |
+
return
|
| 124 |
+
time.sleep(1.0)
|
| 125 |
+
# HTTP not ready yet but deadline not reached — keep outer loop going
|
| 126 |
if _TEXT_ENCODER_SERVER_PROCESS.poll() is not None:
|
| 127 |
raise RuntimeError(
|
| 128 |
"Text encoder server process exited during startup. "
|