Skip to content

Commit

Permalink
Use overrides (#5695)
Browse files Browse the repository at this point in the history
* Use overrides

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot committed Sep 26, 2023
1 parent e19d333 commit 5d60869
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
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

0 comments on commit 5d60869

Please sign in to comment.