o
    5ti                     @   sz   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ eeZdZdd Zed	kr;e  dS dS )
    N)Path)cookiecutter)HfApi
Repositorycreate_repo)
get_loggera  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}.

Here are the next steps:
- implement the module logic in {module_slug}/{module_slug}.py
- document your module in {module_slug}/README.md
- add test cases for your module in {module_slug}/tests.py
- if your module has any dependencies update them in {module_slug}/requirements.txt

You can test your module's widget locally by running:

```
python {output_dir}/{module_slug}/app.py
```

When you are happy with your changes you can push your changes with the following commands to the Hugging Face Hub:

```
cd {output_dir}/{module_slug}
git add .
git commit -m "Updating module"
git push
```

You should then see the update widget on the Hugging Face Hub: {repo_url}
And you can load your module in Python with the following code:

```
from evaluate import load
module = load("{namespace}/{module_slug}")
```
c               
   C   s  t jddd} |  }|jddd}|jdtdd	 |jd
dtdd |jddtdd |jdtdd	 |jdt tdd |jdd tdd |jdddd t| 	 }|d dvr`t
dd|d v rjt
dt|d  }|d! }|d  d"d#}|d u rt }| d$ }n|}||d%< d&| d'| }	zt|d' | d(d)|d* d+ W n ty }
 ztd,| d'| d- |
d }
~
ww tjd.|	  tjtjd/d0|tj d1 t|| d2}td3d4d/||d/d5 |  |d6 |  tt j!|d |d |||	|d7 d S )8NzHuggingFace Evaluate CLI toolzevaluate-cli <command> [<args>])usagecreatezCreate new evaluation module.)helpmodule_namezEPretty name of new evaluation module, e.g. "Recall" or "Exact Match".)typer
   z--module_typemetriczAType of module, has to be one of [metric|comparison|measurement].)defaultr   r
   z--dataset_name z9Name of dataset if evaluation module is dataset specific.z--module_descriptionz'Short description of evaluation module.z--output_dirzPath to output directory.z--organizationz5Organization on the Hub to push evaluation module to.z	--private
store_truez-Sets evaluation module repository to private.)actionr
   module_type)r   
comparisonmeasurementzEThe module_type needs to be one of metric, comparison, or measurement-z.Hyphens ('-') are not allowed in module names.
output_dirorganization _name	namespacezhttps://huggingface.co/spaces//spacegradioprivate)	repo_type	space_sdkr   z2Could not create Space for module at hf.co/spaces/z.. Make sure this space does not exist already.z
git clone Tzutf-8)stderrstdoutcheckencodingcwdenv)	local_dirz(https://github.com/huggingface/evaluate/	templates)	directoryno_inputextra_contextr   overwrite_if_existszadd module default template)r   r   module_slugr   repo_urlr   )"argparseArgumentParseradd_subparsers
add_parseradd_argumentstrr   r&   vars
parse_args
ValueErrorlowerreplacer   whoamir   	Exceptionloggererror
subprocessrunsplitPIPEosenvironcopyr   r   git_add
git_commitgit_pushprintINSTRUCTIONSformat)parser
subparsersparser_createargsr   r   r.   hfapir   r/   	exceptionrepo rS   R/home/ubuntu/.local/lib/python3.10/site-packages/evaluate/commands/evaluate_cli.pymain0   s    
	
rU   __main__)r0   rC   r?   pathlibr   cookiecutter.mainr   huggingface_hubr   r   r   evaluate.utils.loggingr   __name__r=   rJ   rU   rS   rS   rS   rT   <module>   s    "X
