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.
1
Modify the name in pyproject.toml
Update the
name field in the pyproject.toml file:2
Change all occurrences in pyproject.toml
Change all occurrences of
gradio_<component-name> to <component-name>:3
Rename the backend directory
Rename the
gradio_<component-name> directory in backend/ 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:
1
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!2
Move the JavaScript code
Place the JavaScript code in the subdirectory of your choosing.
3
Add the FRONTEND_DIR property
Add the
FRONTEND_DIR property on the component Python class. It must be the relative path from the file where the class is defined to the location of the JavaScript directory.