diff --git a/README.md b/README.md index 8954b04dc..d8963ea4d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/source/creating_and_sharing.mdx b/docs/source/creating_and_sharing.mdx index a15d0445b..c1b96d3fc 100644 --- a/docs/source/creating_and_sharing.mdx +++ b/docs/source/creating_and_sharing.mdx @@ -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. diff --git a/setup.py b/setup.py index ce71525e1..27a7ddc3b 100644 --- a/setup.py +++ b/setup.py @@ -93,6 +93,8 @@ TEMPLATE_REQUIRE = [ # to populate metric template "cookiecutter" + # for the gradio widget + "gradio>=3.0.0" ] EVALUATOR_REQUIRE = [ diff --git a/src/evaluate/commands/evaluate_cli.py b/src/evaluate/commands/evaluate_cli.py index fd1406b86..80593c4df 100644 --- a/src/evaluate/commands/evaluate_cli.py +++ b/src/evaluate/commands/evaluate_cli.py @@ -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}. @@ -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,