{"record":{"id":"d5b001c7fc8439f1","repo":"huggingface/smolagents","slug":"gradio-should-be-installed-in-order-to-launch-a-gr","errorCode":null,"errorMessage":"Gradio should be installed in order to launch a gradio demo.","messagePattern":"Gradio should be installed in order to launch a gradio demo\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/smolagents/tools.py","lineNumber":805,"sourceCode":"                        input_key = next(iter(self.inputs))\n                        tool_input[input_key] = argument\n                return self.langchain_tool.run(tool_input)\n\n        return LangChainToolWrapper(langchain_tool)\n\n\ndef launch_gradio_demo(tool: Tool):\n    \"\"\"\n    Launches a gradio demo for a tool. The corresponding tool class needs to properly implement the class attributes\n    `inputs` and `output_type`.\n\n    Args:\n        tool (`Tool`): The tool for which to launch the demo.\n    \"\"\"\n    try:\n        import gradio as gr\n    except ImportError:\n        raise ImportError(\"Gradio should be installed in order to launch a gradio demo.\")\n\n    TYPE_TO_COMPONENT_CLASS_MAPPING = {\n        \"boolean\": gr.Checkbox,\n        \"image\": gr.Image,\n        \"audio\": gr.Audio,\n        \"string\": gr.Textbox,\n        \"integer\": gr.Number,\n        \"number\": gr.Number,\n    }\n\n    def tool_forward(*args, **kwargs):\n        return tool(*args, sanitize_inputs_outputs=True, **kwargs)\n\n    tool_forward.__signature__ = inspect.signature(tool.forward)\n\n    gradio_inputs = []\n    for input_name, input_details in tool.inputs.items():\n        input_gradio_component_class = TYPE_TO_COMPONENT_CLASS_MAPPING[input_details[\"type\"]]","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/tools.py#L787-L823","documentation":"This ImportError is raised by Tool.launch_gradio_demo when the optional `gradio` dependency is not installed. The method wraps a Tool in an interactive Gradio UI, which requires gradio at runtime. Gradio is an optional extra, so a base `pip install smolagents` does not include it.","triggerScenarios":"Calling `tool.launch_gradio_demo()` (or `agent.launch_gradio_demo()`) on any Tool instance in an environment where `import gradio` fails, e.g. base install without extras or a restricted CI container.","commonSituations":"Running demos in CI, Docker images, or minimal virtualenvs where only core dependencies were installed; gradio was dropped during a dependency cleanup or unpinned environment rebuild.","solutions":["Install gradio: `pip install gradio` (or `pip install 'smolagents[gradio]'` if the extra exists in your version)","Gate the demo launch behind an availability check (importlib.util.find_spec('gradio')) in scripts/CI","Separate demo dependencies into a dev/demo requirements file so interactive UIs are only installed where needed"],"exampleFix":"# before\ntool.launch_gradio_demo()\n# after\nimport importlib.util\nif importlib.util.find_spec(\"gradio\") is None:\n    raise SystemExit(\"Install gradio to run the demo: pip install gradio\")\ntool.launch_gradio_demo()","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec(\"gradio\") is None:\n    print(\"gradio not installed; skipping demo launch\")\nelse:\n    tool.launch_gradio_demo()","typeGuard":null,"tryCatchPattern":"try:\n    tool.launch_gradio_demo()\nexcept ImportError as e:\n    if \"Gradio\" in str(e):\n        print(\"Install gradio to run demos\")\n    else:\n        raise","preventionTips":["Include gradio in dev/demo requirements files","Check find_spec('gradio') before launching demos in shared scripts"],"tags":["gradio","optional-dependency","importerror","demo"],"backgroundTag":"missing-optional-dependency","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}