a-alnaggar
commited on
Commit
•
61e15f9
1
Parent(s):
9d2af50
Upload 2 files
Browse files- khatt-paragraphs.py +66 -0
- khatt-paragraphs.tar.gz +3 -0
khatt-paragraphs.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
from PIL import ImageOps
|
3 |
+
|
4 |
+
_CITATION = """\
|
5 |
+
@InProceedings{huggingface:dataset,
|
6 |
+
title = {Processed KHATT paragrpah dataset},
|
7 |
+
author={Ahmed Alnaggar},
|
8 |
+
year={2024}
|
9 |
+
}
|
10 |
+
"""
|
11 |
+
|
12 |
+
_DESCRIPTION = """\
|
13 |
+
A curated version of KHATT paragraph dataset containing 3996 images and their crossponding Arabic paragraphs
|
14 |
+
"""
|
15 |
+
_HOMEPAGE = "https://huggingface.co/datasets/a-alnaggar/khatt-paragraphs"
|
16 |
+
|
17 |
+
_LICENSE = ""
|
18 |
+
|
19 |
+
_REPO = "https://huggingface.co/datasets/a-alnaggar/khatt-paragraphs"
|
20 |
+
|
21 |
+
class KhattPara(datasets.GeneratorBasedBuilder):
|
22 |
+
|
23 |
+
def _info(self):
|
24 |
+
return datasets.DatasetInfo(
|
25 |
+
description=_DESCRIPTION,
|
26 |
+
features=datasets.Features(
|
27 |
+
{
|
28 |
+
'text': datasets.Value("string"),
|
29 |
+
'image': datasets.Image(),
|
30 |
+
}
|
31 |
+
),
|
32 |
+
supervised_keys=None,
|
33 |
+
homepage=_HOMEPAGE,
|
34 |
+
citation=_CITATION,
|
35 |
+
)
|
36 |
+
|
37 |
+
def _split_generators(self, dl_manager):
|
38 |
+
images_archive = dl_manager.download(f"{_REPO}/resolve/main/khatt-paragraphs.tar.gz")
|
39 |
+
image_iters = dl_manager.iter_archive(images_archive)
|
40 |
+
|
41 |
+
return [
|
42 |
+
datasets.SplitGenerator(
|
43 |
+
name=datasets.Split.TRAIN,
|
44 |
+
gen_kwargs={
|
45 |
+
"image": image_iters,
|
46 |
+
}
|
47 |
+
),
|
48 |
+
]
|
49 |
+
|
50 |
+
def _generate_examples(self, images):
|
51 |
+
"""Returns inverted image and Arabic text."""
|
52 |
+
for idx, (filepath, image) in enumerate(images):
|
53 |
+
text_path = filepath.split('.')[0] + ".txt"
|
54 |
+
text = self.read_arabic_text_file(text_path)
|
55 |
+
|
56 |
+
yield idx, {
|
57 |
+
"image": {"path": filepath, "bytes": ImageOps.invert(image.read())},
|
58 |
+
"text": text,
|
59 |
+
}
|
60 |
+
|
61 |
+
@staticmethod
|
62 |
+
def read_arabic_text_file(file_path):
|
63 |
+
with open(file_path, 'r', encoding='iso-8859-1') as file:
|
64 |
+
lines = file.readlines()
|
65 |
+
return '\n'.join(lines)
|
66 |
+
|
khatt-paragraphs.tar.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cf44d994522cef0553a788d4462f5dd6b99821c8d73f93a85c01f5950c4b4865
|
3 |
+
size 308288654
|