| import os |
| import json |
| import datasets |
|
|
| class FinDocRobust(datasets.GeneratorBasedBuilder): |
| def _info(self): |
| return datasets.DatasetInfo( |
| features=datasets.Features({ |
| "file_name": datasets.Image(), |
| "document_type": datasets.Value("string"), |
| "document_id": datasets.Value("int64"), |
| "clean_pdf": datasets.Value("string"), |
| "clean_xlsx": datasets.Value("string"), |
| "clean_bbox_px": datasets.Value("string"), |
| "clean_bbox_pdf_pt": datasets.Value("string"), |
| **{f"dirty_{i}_image": datasets.Image() for i in range(1, 6)}, |
| **{f"dirty_{i}_bbox": datasets.Value("string") for i in range(1, 6)} |
| }) |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| |
| meta_path = dl_manager.download_and_extract("dataset_index.csv") |
| archive_path = dl_manager.download_and_extract(".") |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={"meta_path": meta_path, "base_path": archive_path} |
| ) |
| ] |
|
|
| def _generate_examples(self, meta_path, base_path): |
| import pandas as pd |
| df = pd.read_csv(meta_path) |
| for idx, row in df.iterrows(): |
| res = { |
| "file_name": os.path.join(base_path, row["file_name"]), |
| "document_type": row["document_type"], |
| "document_id": int(row["document_id"]), |
| "clean_pdf": row["clean_pdf"], |
| "clean_xlsx": row["clean_xlsx"], |
| "clean_bbox_px": row["clean_bbox_px"], |
| "clean_bbox_pdf_pt": row["clean_bbox_pdf_pt"] |
| } |
| for i in range(1, 6): |
| res[f"dirty_{i}_image"] = os.path.join(base_path, row[f"dirty_{i}_image"]) |
| res[f"dirty_{i}_bbox"] = row[f"dirty_{i}_bbox"] |
| yield idx, res |
|
|