arcolab-dev commited on
Commit
a8f2a66
·
verified ·
1 Parent(s): faf0319

Upload FinDoc-Robust.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. FinDoc-Robust.py +48 -0
FinDoc-Robust.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import datasets
4
+
5
+ class FinDocRobust(datasets.GeneratorBasedBuilder):
6
+ def _info(self):
7
+ return datasets.DatasetInfo(
8
+ features=datasets.Features({
9
+ "file_name": datasets.Image(),
10
+ "document_type": datasets.Value("string"),
11
+ "document_id": datasets.Value("int64"),
12
+ "clean_pdf": datasets.Value("string"),
13
+ "clean_xlsx": datasets.Value("string"),
14
+ "clean_bbox_px": datasets.Value("string"),
15
+ "clean_bbox_pdf_pt": datasets.Value("string"),
16
+ **{f"dirty_{i}_image": datasets.Image() for i in range(1, 6)},
17
+ **{f"dirty_{i}_bbox": datasets.Value("string") for i in range(1, 6)}
18
+ })
19
+ )
20
+
21
+ def _split_generators(self, dl_manager):
22
+ # Скачиваем индексный файл и весь репозиторий
23
+ meta_path = dl_manager.download_and_extract("dataset_index.csv")
24
+ archive_path = dl_manager.download_and_extract(".")
25
+ return [
26
+ datasets.SplitGenerator(
27
+ name=datasets.Split.TRAIN,
28
+ gen_kwargs={"meta_path": meta_path, "base_path": archive_path}
29
+ )
30
+ ]
31
+
32
+ def _generate_examples(self, meta_path, base_path):
33
+ import pandas as pd
34
+ df = pd.read_csv(meta_path)
35
+ for idx, row in df.iterrows():
36
+ res = {
37
+ "file_name": os.path.join(base_path, row["file_name"]),
38
+ "document_type": row["document_type"],
39
+ "document_id": int(row["document_id"]),
40
+ "clean_pdf": row["clean_pdf"],
41
+ "clean_xlsx": row["clean_xlsx"],
42
+ "clean_bbox_px": row["clean_bbox_px"],
43
+ "clean_bbox_pdf_pt": row["clean_bbox_pdf_pt"]
44
+ }
45
+ for i in range(1, 6):
46
+ res[f"dirty_{i}_image"] = os.path.join(base_path, row[f"dirty_{i}_image"])
47
+ res[f"dirty_{i}_bbox"] = row[f"dirty_{i}_bbox"]
48
+ yield idx, res