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

Use overrides #5695

Merged
merged 2 commits into from
Sep 26, 2023
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/fresh-ears-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Use overrides
25 changes: 14 additions & 11 deletions gradio/cli/commands/components/_create_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ComponentFiles:


OVERRIDES = {
"JSON": ComponentFiles(template="JSON", python_file_name="json_component"),
"JSON": ComponentFiles(template="JSON", python_file_name="json_component.py"),
"Row": ComponentFiles(
template="Row",
demo_code=textwrap.dedent(
Expand All @@ -51,7 +51,7 @@ class ComponentFiles:
gr.Number(value=10, interactive=True)
"""
),
python_file_name="row",
python_file_name="row.py",
),
"Column": ComponentFiles(
template="Column",
Expand All @@ -63,7 +63,7 @@ class ComponentFiles:
gr.Number(value=10, interactive=True)
"""
),
python_file_name="column",
python_file_name="column.py",
),
"Tabs": ComponentFiles(
template="Tabs",
Expand All @@ -77,7 +77,7 @@ class ComponentFiles:
gr.Number(value=10, interactive=True)
"""
),
python_file_name="tabs",
python_file_name="tabs.py",
),
"Group": ComponentFiles(
template="Group",
Expand All @@ -89,7 +89,7 @@ class ComponentFiles:
gr.Number(value=10, interactive=True)
"""
),
python_file_name="group",
python_file_name="group.py",
),
"Accordion": ComponentFiles(
template="Accordion",
Expand All @@ -101,18 +101,21 @@ class ComponentFiles:
gr.Number(value=10, interactive=True)
"""
),
python_file_name="accordion",
python_file_name="accordion.py",
),
}


def _get_component_code(template: str | None) -> ComponentFiles:
template = template or "Fallback"
return ComponentFiles(
python_file_name=f"{template.lower()}.py",
js_dir=template.lower(),
template=template,
)
if template in OVERRIDES:
return OVERRIDES[template]
else:
return ComponentFiles(
python_file_name=f"{template.lower()}.py",
js_dir=template.lower(),
template=template,
)


def _get_js_dependency_version(name: str, local_js_dir: Path) -> str:
Expand Down
Loading