Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multimodal textbox custom components #8719

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sad-suits-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Fix multimodal textbox custom components
10 changes: 10 additions & 0 deletions gradio/cli/commands/components/_create_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}


Expand Down
6 changes: 5 additions & 1 deletion gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
41 changes: 17 additions & 24 deletions test/test_gradio_component_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down