Datasets:
Youssef Benhachem
commited on
Commit
·
fbce027
1
Parent(s):
471e509
db
Browse files
KHATT.py
CHANGED
@@ -84,7 +84,6 @@ class KHATT(datasets.GeneratorBasedBuilder):
|
|
84 |
},
|
85 |
),
|
86 |
]
|
87 |
-
|
88 |
def _generate_examples(self, archives, split):
|
89 |
"""Yields examples."""
|
90 |
idx = 0
|
@@ -107,6 +106,41 @@ class KHATT(datasets.GeneratorBasedBuilder):
|
|
107 |
else:
|
108 |
text = ""
|
109 |
|
|
|
|
|
|
|
|
|
110 |
ex = {"image": {"path": path, "bytes": file.read()}, "text": text}
|
111 |
yield idx, ex
|
112 |
idx += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
},
|
85 |
),
|
86 |
]
|
|
|
87 |
def _generate_examples(self, archives, split):
|
88 |
"""Yields examples."""
|
89 |
idx = 0
|
|
|
106 |
else:
|
107 |
text = ""
|
108 |
|
109 |
+
elif path.endswith(".txt"):
|
110 |
+
text = file.read()
|
111 |
+
|
112 |
+
|
113 |
ex = {"image": {"path": path, "bytes": file.read()}, "text": text}
|
114 |
yield idx, ex
|
115 |
idx += 1
|
116 |
+
"""
|
117 |
+
def _generate_examples(self, archives, split):
|
118 |
+
|
119 |
+
idx = 0
|
120 |
+
for archive in archives:
|
121 |
+
import ipdb; ipdb.set_trace()
|
122 |
+
for path, file in archive:
|
123 |
+
# If we have an image
|
124 |
+
if path.endswith(".tif"):
|
125 |
+
if split != "test":
|
126 |
+
# image filepath format: <FormNo>_<ParagraphNo>_<LineNo>.TIF
|
127 |
+
root, _ = os.path.splitext(path)
|
128 |
+
txt_path = root + ".txt"
|
129 |
+
# txt_path = path[:-4] + ".txt"
|
130 |
+
|
131 |
+
with open(txt_path, 'r', encoding='utf-8') as file:
|
132 |
+
text = file.read()
|
133 |
+
|
134 |
+
print("hey", text, file)
|
135 |
+
|
136 |
+
else:
|
137 |
+
text = ""
|
138 |
+
|
139 |
+
ex = {"image": {"path": path, "bytes": file.read()}, "text": text}
|
140 |
+
yield idx, ex
|
141 |
+
idx += 1
|
142 |
+
"""
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
+
|