Unable to upload/load a tool.
Author: Romainlg29
Pull request: no

### System Info

- transformers version: 4.31.0
- Platform: Windows-10-10.0.22621-SP0
- Python version: 3.11.3
- Huggingface_hub version: 0.16.4
- Safetensors version: 0.3.1
- Accelerate version: 0.21.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.0.1+cu118 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed

### Who can help?

_No response_

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

When pushing my tool to the hub with the following function, I'm getting an error.

```python
tool.push_to_hub("romainlg/hf-sql")
```

```
Traceback (most recent call last):
  File "d:\Devs\python\ai\tools\sql\main.py", line 4, in <module>
    tool.push_to_hub("romainlg/hf-sql")
  File "C:\Python311\Lib\site-packages\transformers\tools\base.py", line 315, in push_to_hub
    metadata_update(repo_id, {"tags": ["tool"]}, repo_type="space")
  File "C:\Python311\Lib\site-packages\huggingface_hub\utils\_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\repocard.py", line 810, in metadata_update
    return card.push_to_hub(
           ^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\repocard.py", line 275, in push_to_hub
    tmp_path.write_text(str(self))
  File "C:\Python311\Lib\pathlib.py", line 1079, in write_text
    return f.write(data)
           ^^^^^^^^^^^^^
  File "C:\Python311\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f525' in position 27: character maps to <undefined>
```


I bypassed it by saving the tool and then uploading it to the hub but when trying to import it later, I'm getting:

```python
tool.save('./hf-sql-tmp')
```

```python
from transformers import load_tool

sql = load_tool("romainlg/hf-sql")
```

```
Traceback (most recent call last):
  File "d:\Devs\python\ai\tools\sql\test.py", line 5, in <module>
    sql = load_tool("romainlg/hf-sql")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\transformers\tools\base.py", line 690, in load_tool
    return Tool.from_hub(task_or_repo_id, model_repo_id=model_repo_id, token=token, remote=remote, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\transformers\tools\base.py", line 245, in from_hub
    raise EnvironmentError(
OSError: romainlg/hf-sql does not appear to provide a valid configuration in `tool_config.json` or `config.json`.
```

However, by looking at the other working tools, i've the same config base...
I don't know what's the issue here...

The full code is available at [https://huggingface.co/romainlg/hf-sql/tree/main](https://huggingface.co/romainlg/hf-sql/tree/main)

Thank you !


### Expected behavior

Be able to push the tool to the hub and the ability to load the tool from the hub.

Comments:
Hi @Romainlg29, thanks for reporting this issue! 

Could you update the issue information with the full running environment info: run `transformers-cli env` in the terminal and copy-paste the output? 

cc @LysandreJik 

Hi,

I just updated the config, which is:

```
transformers version: 4.31.0
Platform: Windows-10-10.0.22621-SP0
Python version: 3.11.3
Huggingface_hub version: 0.16.4
Safetensors version: 0.3.1
Accelerate version: 0.21.0
Accelerate config: not found
PyTorch version (GPU?): 2.0.1+cu118 (True)
Tensorflow version (GPU?): not installed (NA)
Flax version (CPU?/GPU?/TPU?): not installed (NA)
Jax version: not installed
JaxLib version: not installed
```

Thank you for your reply.

Hi @Romainlg29, thanks for sharing these details. 

I was able to create a tool, push to the hub and can load it both [with](https://huggingface.co/spaces/amyeroberts/test_tool_2/tree/main) and [without](https://huggingface.co/spaces/amyeroberts/test_tool/tree/main) `psycopg2`. 

The main differences I see between these repo and yours are: 
* [the `__init__.py` file](https://huggingface.co/romainlg/hf-sql/blob/main/__init__.py) - you shouldn't need this
* The metadata values shown in the readme [here](https://huggingface.co/romainlg/hf-sql/blob/main/README.md) vs. [here](https://huggingface.co/spaces/amyeroberts/test_tool_2/blob/main/README.md)

I would try and marry up these repos to be as close as possible first and see if we can get yours working. 

The first issue, not being able to push is odd. Could you try pushing something to a different repo name to see if this issue persists?  

Hi @amyeroberts,

I was able to push / retrieve the tool by using another repo name and using WSL.
The first repo was a "model" type repo not a space. That was maybe the issue?

Thank you!