gradio
725eb638 - Auto-discover InferenceClient endpoints in gr.Workflow

Commit
59 days ago
Auto-discover InferenceClient endpoints in gr.Workflow Replace the two hardcoded task tables (`_INFERENCE_ENDPOINT_SCHEMAS`, `_PIPELINE_TAG_TO_ENDPOINT`) with runtime introspection of the `InferenceClient` methods. Adds ~50 lines of discovery, removes ~230 of per-task schemas — net −54 lines — and picks up 3 endpoints that were missing from the hardcoded table (`audio_to_audio`, `table_question_answering`, `zero_shot_image_classification`). Endpoint schemas now derive from method signatures: - port `id` = param name - port `label` = titleized param name - port `type` = name lookup (`image`/`audio`/`video`) or annotation (`int`/`float` → number, `bool` → boolean, else text). Unwraps `Optional[X]` so numeric knobs with a default aren't misclassified as text - port `required` = whether the param has a default - output `type` = derived from method name (`text_to_image` → image, `*_classification` → json, else text) Pipeline-tag → endpoint resolution uses `pipeline_tag.replace("-", "_")` with a small alias table for tags that don't match that convention (`text2text-generation`, `conversational`, `text-to-audio`, and the four vision tags that all route to `chat_completion`). `chat_completion` stays as a synthetic endpoint (hand-crafted `image + prompt → text` shape) merged in after auto-discovery, since it doesn't correspond 1:1 to any InferenceClient method signature. The streaming dispatch, `max_tokens=16384`, `/gradio_api/file=` handling and reasoning-aware error messages added in #13666 are preserved. Also broadens vision routing beyond `image-text-to-text` to also cover `visual-question-answering`, `document-question-answering`, and `image-to-text` — none of these are served as task-specific endpoints by any Inference Provider, so all four now route through `chat_completion` for consistency. Zero-day behavior: when huggingface_hub ships a new task method, adds a param, or changes a param's default, the schema updates automatically with no code change here. New pipeline_tags that don't match any method fall through to the raw inference API path (server-side dispatch). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
Parents
Loading