nielsr HF staff commited on
Commit
c911703
1 Parent(s): 4614328

Add script

Browse files
Files changed (1) hide show
  1. fixtures_ocr.py +78 -0
fixtures_ocr.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import textwrap
16
+ import datasets
17
+ _CITATION = """\\n"""
18
+ _DESCRIPTION = """\\n"""
19
+ class FixturesOCRConfig(datasets.BuilderConfig):
20
+ """BuilderConfig for fixtures OCR"""
21
+ def __init__(
22
+ self,
23
+ data_url,
24
+ url,
25
+ task_templates=None,
26
+ **kwargs,
27
+ ):
28
+ super(FixturesOCRConfig, self).__init__(
29
+ version=datasets.Version("1.9.0", ""), **kwargs
30
+ )
31
+ self.data_url = data_url
32
+ self.url = url
33
+ self.task_templates = task_templates
34
+ class FixturesOCR(datasets.GeneratorBasedBuilder):
35
+ """Fixtures for OCR models. Includes 2 images."""
36
+ BUILDER_CONFIGS = [
37
+ FixturesOCRConfig(
38
+ name="image",
39
+ description=textwrap.dedent(""),
40
+ url="",
41
+ data_url="",
42
+ )
43
+ ]
44
+ DEFAULT_CONFIG_NAME = "image"
45
+ def _info(self):
46
+ return datasets.DatasetInfo(
47
+ description=_DESCRIPTION,
48
+ features=datasets.Features(
49
+ {
50
+ "id": datasets.Value("string"),
51
+ "file": datasets.Value("string"),
52
+ }
53
+ ),
54
+ supervised_keys=("file",),
55
+ homepage=self.config.url,
56
+ citation=_CITATION,
57
+ )
58
+ def _split_generators(self, dl_manager):
59
+ DL_URLS = [
60
+ f"https://huggingface.co/datasets/hf-internal-testing/fixtures_ocr/raw/main/{name}"
61
+ for name in ["SROIE-receipt.jpeg", "iam_picture.jpeg"]
62
+ ]
63
+ archive_path = dl_manager.download_and_extract(DL_URLS)
64
+ return [
65
+ datasets.SplitGenerator(
66
+ name=datasets.Split.TEST,
67
+ gen_kwargs={"archive_path": archive_path},
68
+ ),
69
+ ]
70
+ def _generate_examples(self, archive_path):
71
+ """Generate examples."""
72
+ for i, filename in enumerate(archive_path):
73
+ key = str(i)
74
+ example = {
75
+ "id": key,
76
+ "file": filename,
77
+ }
78
+ yield key, example