Youssef Benhachem commited on
Commit
ccb01a2
1 Parent(s): 8564221
Files changed (1) hide show
  1. KHATT.py +5 -32
KHATT.py CHANGED
@@ -93,9 +93,7 @@ class KHATT(datasets.GeneratorBasedBuilder):
93
  if path.endswith(".tif"):
94
  if split != "test":
95
  # image filepath format: <FormNo>_<ParagraphNo>_<LineNo>.TIF
96
- root, _ = os.path.splitext(path)
97
- txt_path = root + ".txt"
98
- # txt_path = path[:-4] + ".txt"
99
  img_file = file
100
  else:
101
  text = ""
@@ -107,36 +105,11 @@ class KHATT(datasets.GeneratorBasedBuilder):
107
  text = text.decode('utf-8')
108
 
109
  ex = {"image": {"path": path, "bytes": img_file.read()}, "text": text}
110
- yield idx, ex
111
- idx += 1
112
- """
113
- def _generate_examples(self, archives, split):
114
 
115
- idx = 0
116
- for archive in archives:
117
- import ipdb; ipdb.set_trace()
118
- for path, file in archive:
119
- # If we have an image
120
- if path.endswith(".tif"):
121
- if split != "test":
122
- # image filepath format: <FormNo>_<ParagraphNo>_<LineNo>.TIF
123
- root, _ = os.path.splitext(path)
124
- txt_path = root + ".txt"
125
- # txt_path = path[:-4] + ".txt"
126
-
127
- with open(txt_path, 'r', encoding='utf-8') as file:
128
- text = file.read()
129
-
130
- print("hey", text, file)
131
-
132
  else:
133
- text = ""
134
-
135
- ex = {"image": {"path": path, "bytes": file.read()}, "text": text}
136
- yield idx, ex
137
  idx += 1
138
- """
139
-
140
-
141
-
142
 
 
93
  if path.endswith(".tif"):
94
  if split != "test":
95
  # image filepath format: <FormNo>_<ParagraphNo>_<LineNo>.TIF
96
+ source = path.split('/')[0]
 
 
97
  img_file = file
98
  else:
99
  text = ""
 
105
  text = text.decode('utf-8')
106
 
107
  ex = {"image": {"path": path, "bytes": img_file.read()}, "text": text}
 
 
 
 
108
 
109
+ if split == source:
110
+ yield idx, ex
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  else:
112
+ continue
113
+
 
 
114
  idx += 1
 
 
 
 
115