mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
Fix multimodal textbox custom components (#8719)
* Add code * add changeset * Add code * Update comment --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
4221290d84
commit
d15ada9a1c
5
.changeset/sad-suits-burn.md
Normal file
5
.changeset/sad-suits-burn.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Fix multimodal textbox custom components
|
@ -204,6 +204,16 @@ OVERRIDES = {
|
||||
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",
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
@ -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():
|
||||
|
@ -4,39 +4,31 @@ from pathlib import Path
|
||||
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user