Dataset Viewer issue

#2
by luodian - opened
LMMs-Lab org

The dataset viewer is not working.

Error details:

Error code:   ConfigNamesError
Exception:    DatasetWithScriptNotSupportedError
Message:      The dataset viewer doesn't support this dataset because it runs arbitrary python code. Please open a discussion in the discussion tab if you think this is an error and tag 

@lhoestq

	 and 

@severo

	.
Traceback:    Traceback (most recent call last):
                File "/src/services/worker/src/worker/job_runners/dataset/config_names.py", line 65, in compute_config_names_response
                  for config in sorted(get_dataset_config_names(path=dataset, token=hf_token))
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/inspect.py", line 351, in get_dataset_config_names
                  dataset_module = dataset_module_factory(
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/load.py", line 1512, in dataset_module_factory
                  raise e1 from None
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/load.py", line 1481, in dataset_module_factory
                  return HubDatasetModuleFactoryWithScript(
                File "/src/services/worker/src/worker/utils.py", line 400, in raise_unsupported_dataset_with_script_or_init
                  raise DatasetWithScriptNotSupportedError(
              libcommon.exceptions.DatasetWithScriptNotSupportedError: The dataset viewer doesn't support this dataset because it runs arbitrary python code. Please open a discussion in the discussion tab if you think this is an error and tag 

@lhoestq

	 and 

@severo

	.

I've already made a parquet file and why it doesnt display in dataset viewer?

The information inside are:

image.png

cc @albertvillanova @lhoestq @severo

Sometimes it takes some time until the viewer is updated.

Now the viewer is fixed:
Screenshot from 2023-12-21 09-03-03.png

albertvillanova changed discussion status to closed
LMMs-Lab org

hi thanks for your help!

But may I know why it can not display images?

I used the following script to convert images from path to parquet dict.

def convert_image_to_byte_dict(file_path):
    file_path = os.path.join("/raid/bli/data/MME_Images", file_path)
    with Image.open(file_path) as img:
        img_byte_arr = io.BytesIO()
        img.save(img_byte_arr, format=img.format)
        img_bytes = img_byte_arr.getvalue()
        return {"bytes": img_bytes, "path": None}
luodian changed discussion status to open

Hi ! Parquet doesn't have a native type for images, so you need to add Parquet schema metadata to set the Image() type:

import fsspec
import pyarrow.parquet as pq
from datasets import Features, Image

current_schema = pq.read_schema(fsspec.open("https://huggingface.co/datasets/Otter-AI/MME/resolve/main/mme.parquet").open())

features = Features.from_arrow_schema(current_schema)
features["image"] = Image()
schema_with_image_type = features.arrow_schema
print(schema_with_image_type)
# question_id: string
# category: string
# image: struct<bytes: binary, path: string>
#   child 0, bytes: binary
#   child 1, path: string
# question: string
# answer: string
# -- schema metadata --
# huggingface: '{"info": {"features": {"question_id": {"dtype": "string", "' + 199

# Now your should write your parquet file using `schema=schema_with_image_type`
LMMs-Lab org

that's nice, thank you!

luodian changed discussion status to closed

Or using datasets:

from datasets import Dataset, Image

ds = Dataset.from_parquet("https://huggingface.co/datasets/Otter-AI/MME/resolve/main/mme.parquet")
ds = ds.cast_column("image", Image())
ds.push_to_hub("Otter-AI/MME")
# or ds.to_parquet("path/to_local/mme.parquet")

Sign up or log in to comment