Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat: add configurable local API startup timeout for Gradio integration

myhloli8422cf2deef7
diff --git a/mineru/cli/api_client.py b/mineru/cli/api_client.py
index 63d91eff..51a766f5 100644
--- a/mineru/cli/api_client.py
+++ b/mineru/cli/api_client.py
@@ -31,12 +31,48 @@ HEALTH_ENDPOINT = "/health"
TASKS_ENDPOINT = "/tasks"
TASK_STATUS_POLL_INTERVAL_SECONDS = 1.0
TASK_RESULT_TIMEOUT_SECONDS = 3600
-LOCAL_API_STARTUP_TIMEOUT_SECONDS = 30
LOCAL_API_SHUTDOWN_TIMEOUT_SECONDS = 10
LOCAL_API_CLEANUP_RETRIES = 8
LOCAL_API_CLEANUP_RETRY_INTERVAL_SECONDS = 0.25
+def get_float_env(name: str, default: float, minimum: float = 0.0) -> float:
+ value = os.getenv(name)
+ if value is None:
+ return default
+ try:
+ resolved = float(value)
+ except ValueError:
+ logger.warning(
+ "Invalid {} value: {}. Expected a number, using default {}.",
+ name,
+ value,
+ default,
+ )
+ return default
+ if resolved < minimum:
+ logger.warning(
+ "Invalid {} value: {}. Expected a number >= {}, using default {}.",
+ name,
+ value,
+ minimum,
+ default,
+ )
+ return default
+ return resolved
+
+
+def get_local_api_startup_timeout_seconds(default: float = 300.0) -> float:
+ return get_float_env(
+ "MINERU_LOCAL_API_STARTUP_TIMEOUT_SECONDS",
+ default,
+ minimum=1.0,
+ )
+
+
+LOCAL_API_STARTUP_TIMEOUT_SECONDS = get_local_api_startup_timeout_seconds()
+
+
@dataclass(frozen=True)
class UploadAsset:
path: Path
diff --git a/mineru/cli/gradio_app.py b/mineru/cli/gradio_app.py
index 371f470c..8c2d64b5 100644
--- a/mineru/cli/gradio_app.py
+++ b/mineru/cli/gradio_app.py
@@ -536,7 +536,9 @@ async def resolve_server_health(http_client, api_url):
return await _api_client.wait_for_local_api_ready(http_client, local_server)
-async def ensure_local_api_ready_for_gradio_startup():
+async def ensure_local_api_ready_for_gradio_startup(
+ timeout_seconds: float = _api_client.LOCAL_API_STARTUP_TIMEOUT_SECONDS,
+):
local_server, started_now = _gradio_local_api_server.ensure_started()
if started_now:
logger.info(f"Started local mineru-api at {local_server.base_url}")
@@ -545,7 +547,11 @@ async def ensure_local_api_ready_for_gradio_startup():
timeout=_api_client.build_http_timeout(),
follow_redirects=True,
) as http_client:
- return await _api_client.wait_for_local_api_ready(http_client, local_server)
+ return await _api_client.wait_for_local_api_ready(
+ http_client,
+ local_server,
+ timeout_seconds=timeout_seconds,
+ )
def maybe_prepare_local_api_for_gradio_startup(