Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
65 changes: 0 additions & 65 deletions README.md

This file was deleted.

6 changes: 6 additions & 0 deletions docs/source/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ your kernel builds to the Hub. To know the supported arguments run: `kernels upl
- If a repo with the `repo_id` already exists and if it contains a `build` with the build variant
being uploaded, it will attempt to delete the files existing under it.
- Make sure to be authenticated (run `hf auth login` if not) to be able to perform uploads to the Hub.

### kernels create-and-upload-card

Use `kernels create-and-upload-card <kernel_source_dir> --card-path README.md` to generate a basic homepage
for the kernel. Find an example [here](https://hf.co/kernels-community/kernel-card-template). You can
optionally push it to the Hub by specifying a `--repo-id`.
2 changes: 1 addition & 1 deletion kernels/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ kernels = "kernels.cli:main"
"kernels.lock" = "kernels.lockfile:write_egg_lockfile"

[tool.setuptools.package-data]
kernels = ["python_depends.json"]
kernels = ["python_depends.json", "card_template.md"]

[tool.isort]
profile = "black"
Expand Down
34 changes: 34 additions & 0 deletions kernels/src/kernels/card_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
{{ card_data }}
---

<!-- This model card has automatically been generated. You
should probably proofread and complete it, then remove this comment. -->

{{ model_description }}

## How to use

```python
# TODO: add an example code snippet for running this kernel
```

## Available functions

[TODO: add the functions available through this kernel]

## Supported backends

[TODO: add the backends this kernel supports]

## Benchmarks

[TODO: provide benchmarks if available]

## Code source

[TODO: provide original code source and other relevant citations if available]

## Notes

[TODO: provide additional notes about this kernel if needed]
69 changes: 69 additions & 0 deletions kernels/src/kernels/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
)
from kernels.versions_cli import print_kernel_versions
from kernels.init import run_init, parse_kernel_name
from kernels.kernel_card_utils import (
_load_or_create_kernel_card,
_update_benchmark,
_update_kernel_card_available_funcs,
_update_kernel_card_license,
_update_kernel_card_backends,
_update_kernel_card_usage,
)

from .doc import generate_readme_for_kernel

Expand Down Expand Up @@ -181,6 +189,37 @@ def main():
)
init_parser.set_defaults(func=run_init)

repocard_parser = subparsers.add_parser(
"create-and-upload-card",
help="Create and optionally upload a kernel card.",
)
repocard_parser.add_argument(
"kernel_dir",
type=str,
help="Path to the kernels source.",
)
repocard_parser.add_argument(
"--card-path", type=str, required=True, help="Path to save the card to."
)
repocard_parser.add_argument(
"--description",
type=str,
default=None,
help="Description to introduce the kernel.",
)
repocard_parser.add_argument(
"--repo-id",
type=str,
default=None,
help="If specified it will be pushed to a repository on the Hub.",
)
repocard_parser.add_argument(
"--create-pr",
action="store_true",
help="If specified it will create a PR on the `repo_id`.",
)
repocard_parser.set_defaults(func=create_and_upload_card)

args = parser.parse_args()
args.func(args)

Expand Down Expand Up @@ -249,6 +288,36 @@ def upload_kernels(args):
)


def create_and_upload_card(args):
if not args.repo_id and args.create_pr:
raise ValueError("`create_pr` cannot be True when `repo_id` is None.")

kernel_dir = Path(args.kernel_dir).resolve()
kernel_card = _load_or_create_kernel_card(
kernel_description=args.description, license="apache-2.0"
)

updated_card = _update_kernel_card_usage(
kernel_card=kernel_card, local_path=kernel_dir
)
updated_card = _update_kernel_card_available_funcs(
kernel_card=kernel_card, local_path=kernel_dir
)
updated_card = _update_kernel_card_backends(
kernel_card=kernel_card, local_path=kernel_dir
)
updated_card = _update_benchmark(kernel_card=kernel_card, local_path=kernel_dir)
updated_card = _update_kernel_card_license(
kernel_card=kernel_card, local_path=kernel_dir
)

card_path = args.card_path
updated_card.save(card_path)

if args.repo_id:
updated_card.push_to_hub(repo_id=args.repo_id, create_pr=args.create_pr)


class _JSONEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
Expand Down
Loading
Loading