nielsr HF staff commited on
Commit
8a62099
1 Parent(s): f87c544

First commit

Browse files
Files changed (3) hide show
  1. document.png +0 -0
  2. document_2.png +0 -0
  3. fixtures_docvqa.py +94 -0
document.png ADDED
document_2.png ADDED
fixtures_docvqa.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ import textwrap
18
+
19
+ import datasets
20
+
21
+
22
+ _CITATION = """\\n"""
23
+
24
+ _DESCRIPTION = """\\n"""
25
+
26
+
27
+ class FixturesDocVQAConfig(datasets.BuilderConfig):
28
+ """BuilderConfig for fixtures DocVQA"""
29
+
30
+ def __init__(
31
+ self,
32
+ data_url,
33
+ url,
34
+ task_templates=None,
35
+ **kwargs,
36
+ ):
37
+ super(FixturesDocVQAConfig, self).__init__(
38
+ version=datasets.Version("1.9.0", ""), **kwargs
39
+ )
40
+ self.data_url = data_url
41
+ self.url = url
42
+ self.task_templates = task_templates
43
+
44
+
45
+ class FixturesDocVQA(datasets.GeneratorBasedBuilder):
46
+ """Fixtures of the DocVQA dataset. Include 2 document images."""
47
+
48
+ BUILDER_CONFIGS = [
49
+ FixturesDocVQAConfig(
50
+ name="image",
51
+ description=textwrap.dedent(""),
52
+ url="",
53
+ data_url="",
54
+ )
55
+ ]
56
+
57
+ DEFAULT_CONFIG_NAME = "image"
58
+
59
+ def _info(self):
60
+ return datasets.DatasetInfo(
61
+ description=_DESCRIPTION,
62
+ features=datasets.Features(
63
+ {
64
+ "id": datasets.Value("string"),
65
+ "file": datasets.Value("string"),
66
+ }
67
+ ),
68
+ supervised_keys=("file",),
69
+ homepage=self.config.url,
70
+ citation=_CITATION,
71
+ )
72
+
73
+ def _split_generators(self, dl_manager):
74
+ DL_URLS = [
75
+ f"https://huggingface.co/datasets/hf-internal-testing/fixtures_docvqa/raw/main/{name}"
76
+ for name in ["document.png", "document_2.png"]
77
+ ]
78
+ archive_path = dl_manager.download_and_extract(DL_URLS)
79
+ return [
80
+ datasets.SplitGenerator(
81
+ name=datasets.Split.TEST,
82
+ gen_kwargs={"archive_path": archive_path},
83
+ ),
84
+ ]
85
+
86
+ def _generate_examples(self, archive_path):
87
+ """Generate examples."""
88
+ for i, filename in enumerate(archive_path):
89
+ key = str(i)
90
+ example = {
91
+ "id": key,
92
+ "file": filename,
93
+ }
94
+ yield key, example