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

Update CLI docs #218

Merged
merged 6 commits into from
Jul 29, 2022
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ pip install evaluate
# Adding a new evaluation module

First install the necessary dependencies to create a new metric with the following command:
```
```bash
pip install evaluate[template]
```
Then you can get started with the following command which will create a new folder for your metric and display the necessary steps:
```batch
```bash
evaluate-cli create "Awesome Metric"
```
See this [step-by-step guide](https://huggingface.co/docs/evaluate/creating_and_sharing) in the documentation for detailed instructions.
Expand Down
19 changes: 18 additions & 1 deletion docs/source/creating_and_sharing.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
# Creating and sharing a new evaluation

## Setup

Before you can create a new metric make sure you have all the necessary dependencies installed:

```bash
pip install evaluate[template]
```

Also make sure your Hugging Face token is registered so you can connect to the Hugging Face Hub:

```bash
huggingface-cli login
```

## Create

All evaluation modules, be it metrics, comparisons, or measurements live on the 🤗 Hub in a [Space](https://huggingface.co/docs/hub/spaces) (see for example [Accuracy](https://huggingface.co/spaces/evaluate-metric/accuracy)). In principle, you could setup a new Space and add a new module following the same structure. However, we added a CLI that makes creating a new evaluation module much easier:

```bash
evaluate-cli create "My Metric" module_type="metric"
evaluate-cli create "My Metric" --module_type "metric"
```

This will create a new Space on the 🤗 Hub, clone it locally, and populate it with a template. Instructions on how to fill the template will be displayed in the terminal, but are also explained here in more detail.

For more information about Spaces, see the [Spaces documentation](https://huggingface.co/docs/hub/spaces).

## Module script

The evaluation module script (the file with suffix `*.py`) is the core of the new module and includes all the code for computing the evaluation.
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
TEMPLATE_REQUIRE = [
# to populate metric template
"cookiecutter"
# for the gradio widget
"gradio>=3.0.0"
]

EVALUATOR_REQUIRE = [
Expand Down
12 changes: 11 additions & 1 deletion src/evaluate/commands/evaluate_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from cookiecutter.main import cookiecutter
from huggingface_hub import HfApi, Repository, create_repo

from evaluate.utils.logging import get_logger


logger = get_logger(__name__)

INSTRUCTIONS = """\
A new repository for your module "{module_name}" of type "{module_type}" has been created at {output_dir} and pushed to the Hugging Face Hub: {repo_url}.
Expand Down Expand Up @@ -83,7 +87,13 @@ def main():
args["namespace"] = namespace
repo_url = f"https://huggingface.co/spaces/{namespace}/{module_slug}"

create_repo(namespace + "/" + module_slug, repo_type="space", space_sdk="gradio", private=args["private"])
try:
create_repo(namespace + "/" + module_slug, repo_type="space", space_sdk="gradio", private=args["private"])
except Exception as exception:
logger.error(
f"Could not create Space for module at hf.co/spaces/{namespace}/{module_slug}. Make sure this space does not exist already."
)
raise exception
subprocess.run(
f"git clone {repo_url}".split(),
stderr=subprocess.PIPE,
Expand Down