The custom components workflow focuses on convention over configuration to reduce the number of decisions you as a developer need to make when developing your custom component. That being said, you can still configure some aspects of the custom component package and directory. This guide will cover how.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
Use this file to discover all available pages before exploring further.
The package name
By default, all custom component packages are calledgradio_<component-name> where component-name is the name of the component’s Python class in lowercase.
As an example, let’s walkthrough changing the name of a component from gradio_mytextbox to supertextbox.
Change all occurrences in pyproject.toml
Change all occurrences of
gradio_<component-name> to <component-name>:Top level Python exports
By default, only the custom component Python class is a top level export. This means that when users typefrom gradio_<component-name> import ..., the only class that will be available is the custom component class.
To add more classes as top level exports, modify the __all__ property in __init__.py:
Python dependencies
You can add Python dependencies by modifying thedependencies key in pyproject.toml:
JavaScript dependencies
You can add JavaScript dependencies by modifying the"dependencies" key in frontend/package.json:
Directory structure
By default, the CLI will place the Python code inbackend and the JavaScript code in frontend. It is not recommended to change this structure since it makes it easy for a potential contributor to look at your source code and know where everything is.
However, if you did want to, this is what you would have to do:
Move the Python code
Place the Python code in the subdirectory of your choosing. Remember to modify the
[tool.hatch.build] and [tool.hatch.build.targets.wheel] in the pyproject.toml to match!