diff --git a/.changeset/sad-suits-burn.md b/.changeset/sad-suits-burn.md new file mode 100644 index 000000000000..45915b59d314 --- /dev/null +++ b/.changeset/sad-suits-burn.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:Fix multimodal textbox custom components diff --git a/gradio/cli/commands/components/_create_utils.py b/gradio/cli/commands/components/_create_utils.py index 81e220ec96d0..10f9b5bf4620 100644 --- a/gradio/cli/commands/components/_create_utils.py +++ b/gradio/cli/commands/components/_create_utils.py @@ -204,6 +204,16 @@ def __post_init__(self): python_file_name="image_editor.py", js_dir="imageeditor", ), + "MultimodalTextbox": ComponentFiles( + template="MultimodalTextbox", + python_file_name="multimodal_textbox.py", + js_dir="multimodaltextbox", + ), + "DownloadButton": ComponentFiles( + template="DownloadButton", + python_file_name="download_button.py", + js_dir="downloadbutton", + ), } diff --git a/gradio/utils.py b/gradio/utils.py index 3fb7a1272c75..13fb16a2c047 100644 --- a/gradio/utils.py +++ b/gradio/utils.py @@ -559,7 +559,11 @@ def get_all_components() -> list[type[Component] | type[BlockContext]]: subclass = classes_to_check.pop() classes_to_check.extend(subclass.__subclasses__()) subclasses.append(subclass) - return subclasses + return [ + c + for c in subclasses + if c.__name__ not in ["ChatInterface", "Interface", "Blocks", "TabbedInterface"] + ] def core_gradio_components(): diff --git a/test/test_gradio_component_cli.py b/test/test_gradio_component_cli.py index d4d4ad987246..7a6e02b996a6 100644 --- a/test/test_gradio_component_cli.py +++ b/test/test_gradio_component_cli.py @@ -4,39 +4,31 @@ import pytest -from gradio.cli.commands.components._create_utils import OVERRIDES from gradio.cli.commands.components.build import _build -from gradio.cli.commands.components.create import _create +from gradio.cli.commands.components.create import _create, _create_utils from gradio.cli.commands.components.install_component import _get_executable_path from gradio.cli.commands.components.publish import _get_version_from_file from gradio.cli.commands.components.show import _show +from gradio.utils import core_gradio_components + +core = [ + c.__name__ + for c in core_gradio_components() + if not getattr(c, "is_template", False) + and c.__name__ not in ["Tab", "Form", "FormComponent"] +] @pytest.mark.parametrize( "template", - [ - "Row", - "Column", - "Tabs", - "Group", - "Accordion", - "AnnotatedImage", - "HighlightedText", - "BarPlot", - "ClearButton", - "ColorPicker", - "DuplicateButton", - "LinePlot", - "LogoutButton", - "LoginButton", - "ScatterPlot", - "UploadButton", - "JSON", - "FileExplorer", - "Model3D", - ], + core, ) def test_template_override_component(template, tmp_path): + """When you add a new component this test will likely fail locally + because the js files have not been moved to the _frontend_code directory. + + Just build the python package (python -m build -w) to move the latest state of the js directory to _frontend_code. + """ _create( "MyComponent", tmp_path, @@ -46,12 +38,13 @@ def test_template_override_component(template, tmp_path): configure_metadata=False, ) app = (tmp_path / "demo" / "app.py").read_text() + component_files = _create_utils._get_component_code(template) answer = textwrap.dedent( f""" import gradio as gr from gradio_mycomponent import MyComponent -{OVERRIDES[template].demo_code.format(name="MyComponent")} +{component_files.demo_code.format(name="MyComponent")} if __name__ == "__main__": demo.launch()