import os import datasets class Demo(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( features=datasets.Features({ "id": datasets.Value("string"), "problem": datasets.Value("string"), "solution": datasets.Value("string"), "image": datasets.Image(), # Enables image previews "img_height": datasets.Value("int32"), "img_width": datasets.Value("int32"), }), ) def _split_generators(self, dl_manager): # Get the data files from the config data_files = dl_manager.download_and_extract(self.config.data_files) base_path = dl_manager.download_and_extract(".") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_files["train"], "base_path": base_path} ), ] def _generate_examples(self, filepath, base_path): import pandas as pd df = pd.read_parquet(filepath) for idx, row in df.iterrows(): # Handle image path correctly if isinstance(row["image"], dict) and "path" in row["image"]: image_path = os.path.join(base_path, row["image"]["path"]) else: image_path = str(row["image"]) yield idx, { "id": str(row["id"]), "problem": str(row["problem"]), "solution": str(row["solution"]), "image": image_path, # Full path to the image "img_height": int(row["img_height"]), "img_width": int(row["img_width"]), }