Issue: Common Voice 8 doesn't show datasets viewer
State: closed
Author: patrickvonplaten

https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0

Comments:
Thanks for reporting. I understand it's an error in the dataset script. To reproduce:

```python
>>> import datasets as ds
>>> split_names = ds.get_dataset_split_names("mozilla-foundation/common_voice_8_0", use_auth_token="**********")
Downloading builder script: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10.9k/10.9k [00:00<00:00, 10.9MB/s]
Downloading extra modules: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2.98k/2.98k [00:00<00:00, 3.36MB/s]
Downloading extra modules: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 53.1k/53.1k [00:00<00:00, 650kB/s]
No config specified, defaulting to: common_voice/en
Traceback (most recent call last):
  File "/home/slesage/hf/datasets-preview-backend/libs/libmodels/.venv/lib/python3.9/site-packages/datasets/inspect.py", line 280, in get_dataset_config_info
    for split_generator in builder._split_generators(
  File "/home/slesage/.cache/huggingface/modules/datasets_modules/datasets/mozilla-foundation--common_voice_8_0/720589e6e5ad674019008b719053303a71716db1b27e63c9846df02fdf93f2f3/common_voice_8_0.py", line 153, in _split_generators
    self._log_download(self.config.name, bundle_version, hf_auth_token)
  File "/home/slesage/.cache/huggingface/modules/datasets_modules/datasets/mozilla-foundation--common_voice_8_0/720589e6e5ad674019008b719053303a71716db1b27e63c9846df02fdf93f2f3/common_voice_8_0.py", line 139, in _log_download
    email = HfApi().whoami(auth_token)["email"]
KeyError: 'email'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slesage/hf/datasets-preview-backend/libs/libmodels/.venv/lib/python3.9/site-packages/datasets/inspect.py", line 323, in get_dataset_split_names
    info = get_dataset_config_info(
  File "/home/slesage/hf/datasets-preview-backend/libs/libmodels/.venv/lib/python3.9/site-packages/datasets/inspect.py", line 285, in get_dataset_config_info
    raise SplitsNotFoundError("The split names could not be parsed from the dataset config.") from err
datasets.inspect.SplitsNotFoundError: The split names could not be parsed from the dataset config.
```

Thanks for reporting @patrickvonplaten and thanks for the investigation @severo.

Unfortunately I'm not able to reproduce the error.

I think the error has to do with authentication with `huggingface_hub`, because the exception is thrown from these code lines: https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0/blob/main/common_voice_8_0.py#L137-L139
```python
from huggingface_hub import HfApi, HfFolder

if isinstance(auth_token, bool):
    email = HfApi().whoami(auth_token)
email = HfApi().whoami(auth_token)["email"]
```

Could you please verify the previous code with the `auth_token` you pass to `load_dataset(..., use_auth_token=auth_token,...`?

OK, thanks for digging a bit into it. Indeed, the error occurs with the dataset-viewer, but not with a normal user token, because we use an app token, and it does not have a related email!

```python
>>> from huggingface_hub import HfApi, HfFolder
>>> auth_token = "hf_app_******"
>>> t = HfApi().whoami(auth_token)
>>> t
{'type': 'app', 'name': 'dataset-preview-backend'}
>>> t["email"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'email'
```

Note also that the doc (https://huggingface.co/docs/huggingface_hub/package_reference/hf_api#huggingface_hub.HfApi.whoami) does not state that `whoami` should return an `email` key.

@SBrandeis @julien-c: do you think the app token should have an email associated, like the users?

We can workaround this with
```python
email = HfApi().whoami(auth_token).get("email", "system@huggingface.co")
```
in the common voice scripts

Hmmm, does this mean that any person who downloads the common voice dataset will be logged as "system@huggingface.co"? If so, it would defeat the purpose of sending the user's email to the commonvoice API, right?

I agree with @severo: we cannot set our system email as default, allowing anybody not authenticated to by-pass the Common Voice usage policy.

Additionally, looking at the code, I think we should implement a more robust way to send user email to Common Voice: currently anybody can tweak the script and send somebody else email instead.

CC: @patrickvonplaten @lhoestq @SBrandeis @julien-c 

Hmm I don't agree here. 

Anybody can always just bypass the system by setting whatever email. As soon as someone has access to the downloading script it's trivial to tweak the code to not send the "correct" email but to just whatever and it would work.

Note that someone only has visibility on the code after having "signed" the access-mechanism so I think we can expect the users to have agreed to not do anything malicious. 

I'm fine with both @lhoestq's solution or we find a way that forces the user to be logged in + being able to load the data for the datasets viewer. Wdyt @lhoestq @severo @albertvillanova ?

> Additionally, looking at the code, I think we should implement a more robust way to send user email to Common Voice: currently anybody can tweak the script and send somebody else email instead.

Yes, I agree we can forget about this @patrickvonplaten. After having had a look at Common Voice website, I've seen they only require sending an email (no auth is inplace on their side, contrary to what I had previously thought). Therefore, currently we impose stronger requirements than them: we require the user having logged in and accepted the access mechanism.

Currently the script as it is already requires the user being logged in:
```python
HfApi().whoami(auth_token)
```
throws an exception if None/invalid auth_token is passed.

On the other hand, we should agree on the way to allow the viewer to stream the data.

The preview is back now, thanks !