Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: add configurable local API startup timeout for Gradio integration
myhloli8422cf2deef7
diff --git a/mineru/cli/api_client.py b/mineru/cli/api_client.pyindex 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.0TASK_RESULT_TIMEOUT_SECONDS = 3600-LOCAL_API_STARTUP_TIMEOUT_SECONDS = 30LOCAL_API_SHUTDOWN_TIMEOUT_SECONDS = 10LOCAL_API_CLEANUP_RETRIES = 8LOCAL_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: Pathdiff --git a/mineru/cli/gradio_app.py b/mineru/cli/gradio_app.pyindex 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(