Compliance Fix: Resolver setup timeout with lazy Gradio and extended 120s wait
Browse files- inference.py +10 -1
- server/app.py +11 -3
inference.py
CHANGED
|
@@ -305,7 +305,16 @@ async def main() -> None:
|
|
| 305 |
if not setup_error:
|
| 306 |
try:
|
| 307 |
if IMAGE_NAME:
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
else:
|
| 310 |
local_url = os.environ.get("ENV_BASE_URL", "http://127.0.0.1:7860")
|
| 311 |
env = PolicyEvolverEnv(base_url=local_url)
|
|
|
|
| 305 |
if not setup_error:
|
| 306 |
try:
|
| 307 |
if IMAGE_NAME:
|
| 308 |
+
# Manually handle Docker startup to override the 30s library default
|
| 309 |
+
from openenv.core.containers.runtime.providers import LocalDockerProvider
|
| 310 |
+
provider = LocalDockerProvider()
|
| 311 |
+
base_url = provider.start_container(IMAGE_NAME)
|
| 312 |
+
|
| 313 |
+
print(f"[DEBUG] Waiting for container {IMAGE_NAME} at {base_url} (Extended Timeout 120s)...", flush=True)
|
| 314 |
+
provider.wait_for_ready(base_url, timeout_s=120.0)
|
| 315 |
+
|
| 316 |
+
env = PolicyEvolverEnv(base_url=base_url, provider=provider)
|
| 317 |
+
await env.connect()
|
| 318 |
else:
|
| 319 |
local_url = os.environ.get("ENV_BASE_URL", "http://127.0.0.1:7860")
|
| 320 |
env = PolicyEvolverEnv(base_url=local_url)
|
server/app.py
CHANGED
|
@@ -387,9 +387,17 @@ def build_custom_ui():
|
|
| 387 |
|
| 388 |
return demo
|
| 389 |
|
| 390 |
-
#
|
| 391 |
-
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
def main():
|
| 395 |
# Sync with Hugging Face and local requirements
|
|
|
|
| 387 |
|
| 388 |
return demo
|
| 389 |
|
| 390 |
+
# Lazy Gradio UI Mounting
|
| 391 |
+
@app.on_event("startup")
|
| 392 |
+
async def startup_event():
|
| 393 |
+
import gradio as gr
|
| 394 |
+
# Import locally to avoid module-level overhead
|
| 395 |
+
try:
|
| 396 |
+
custom_demo = build_custom_ui()
|
| 397 |
+
gr.mount_gradio_app(app, custom_demo, path="/dashboard/")
|
| 398 |
+
print("[INFO] PolicyEvolver Dashboard mounted at /dashboard/")
|
| 399 |
+
except Exception as e:
|
| 400 |
+
print(f"[WARNING] Failed to mount Gradio Dashboard: {e}")
|
| 401 |
|
| 402 |
def main():
|
| 403 |
# Sync with Hugging Face and local requirements
|