Florent Gbelidji commited on
Sync DeepSeek OCR HF job code
Browse files- ds_batch_ocr/stages.py +11 -23
ds_batch_ocr/stages.py
CHANGED
|
@@ -138,7 +138,6 @@ def _dataset_features() -> Features:
|
|
| 138 |
"source_image_path": HfImage(),
|
| 139 |
"document_with_boxes_image_path": HfImage(),
|
| 140 |
"document_markdown_text": Value("string"),
|
| 141 |
-
"figure_images": Sequence(HfImage()),
|
| 142 |
"figures": Sequence(
|
| 143 |
{
|
| 144 |
"figure_id": Value("string"),
|
|
@@ -163,7 +162,6 @@ def _build_dataset_records_iter(documents: Iterable[Dict[str, Any]]) -> Iterable
|
|
| 163 |
document_with_boxes_path = doc.get("document_with_boxes_path")
|
| 164 |
document_with_boxes_relpath = str(document_with_boxes_path)
|
| 165 |
|
| 166 |
-
figure_images: List[str] = []
|
| 167 |
figure_entries: List[Dict[str, Any]] = []
|
| 168 |
for figure in doc.get("figures") or []:
|
| 169 |
if not isinstance(figure, dict):
|
|
@@ -172,10 +170,12 @@ def _build_dataset_records_iter(documents: Iterable[Dict[str, Any]]) -> Iterable
|
|
| 172 |
raw_image_path = figure.get("image_path")
|
| 173 |
image_relpath = str(raw_image_path)
|
| 174 |
|
| 175 |
-
figure_images.append(image_relpath)
|
| 176 |
figure_entries.append(
|
| 177 |
{
|
| 178 |
-
"figure_id": str(
|
|
|
|
|
|
|
|
|
|
| 179 |
"image_path": image_relpath,
|
| 180 |
"description": str(figure.get("description")),
|
| 181 |
|
|
@@ -183,16 +183,15 @@ def _build_dataset_records_iter(documents: Iterable[Dict[str, Any]]) -> Iterable
|
|
| 183 |
)
|
| 184 |
yield {
|
| 185 |
"sample_id": str(doc.get("sample_id")),
|
| 186 |
-
"dataset_index": int(doc.get("dataset_index")),
|
| 187 |
-
"source_image_path": str(doc.get("source_image_path")),
|
| 188 |
"document_with_boxes_image_path": document_with_boxes_relpath,
|
| 189 |
-
"document_markdown_text": doc.get("document_markdown_text"),
|
| 190 |
-
"figure_images": figure_images,
|
| 191 |
"figures": figure_entries,
|
| 192 |
-
"document_markdown_path": str(doc.get("document_path")),
|
| 193 |
-
"document_final_markdown_path": str(doc.get("document_final_markdown_path")),
|
| 194 |
-
"document_final_markdown_text": doc.get("document_final_markdown_text"),
|
| 195 |
-
"raw_response_path": str(doc.get("raw_response_path")),
|
| 196 |
}
|
| 197 |
|
| 198 |
|
|
@@ -231,15 +230,6 @@ def _push_dataset_records(
|
|
| 231 |
else:
|
| 232 |
data = dict(record)
|
| 233 |
|
| 234 |
-
if "figure_images" not in data or data["figure_images"] is None:
|
| 235 |
-
figure_images = []
|
| 236 |
-
for fig in data.get("figures", []) or []:
|
| 237 |
-
if isinstance(fig, dict):
|
| 238 |
-
image_path = fig.get("image_path")
|
| 239 |
-
if image_path:
|
| 240 |
-
figure_images.append(str(image_path))
|
| 241 |
-
data["figure_images"] = figure_images
|
| 242 |
-
|
| 243 |
yield data
|
| 244 |
|
| 245 |
write_jsonl_iter(dataset_path, _record_iterator())
|
|
@@ -267,8 +257,6 @@ def _load_dataset_records(path: Path) -> List[Dict[str, Any]]:
|
|
| 267 |
record = json.loads(line)
|
| 268 |
if record.get("figures") is None:
|
| 269 |
record["figures"] = []
|
| 270 |
-
if record.get("figure_images") is None:
|
| 271 |
-
record["figure_images"] = []
|
| 272 |
records.append(record)
|
| 273 |
return records
|
| 274 |
|
|
|
|
| 138 |
"source_image_path": HfImage(),
|
| 139 |
"document_with_boxes_image_path": HfImage(),
|
| 140 |
"document_markdown_text": Value("string"),
|
|
|
|
| 141 |
"figures": Sequence(
|
| 142 |
{
|
| 143 |
"figure_id": Value("string"),
|
|
|
|
| 162 |
document_with_boxes_path = doc.get("document_with_boxes_path")
|
| 163 |
document_with_boxes_relpath = str(document_with_boxes_path)
|
| 164 |
|
|
|
|
| 165 |
figure_entries: List[Dict[str, Any]] = []
|
| 166 |
for figure in doc.get("figures") or []:
|
| 167 |
if not isinstance(figure, dict):
|
|
|
|
| 170 |
raw_image_path = figure.get("image_path")
|
| 171 |
image_relpath = str(raw_image_path)
|
| 172 |
|
|
|
|
| 173 |
figure_entries.append(
|
| 174 |
{
|
| 175 |
+
"figure_id": str(
|
| 176 |
+
figure.get("figure_id")
|
| 177 |
+
or figure.get("id")
|
| 178 |
+
),
|
| 179 |
"image_path": image_relpath,
|
| 180 |
"description": str(figure.get("description")),
|
| 181 |
|
|
|
|
| 183 |
)
|
| 184 |
yield {
|
| 185 |
"sample_id": str(doc.get("sample_id")),
|
| 186 |
+
"dataset_index": int(doc.get("dataset_index") or 0),
|
| 187 |
+
"source_image_path": str(doc.get("source_image_path") or ""),
|
| 188 |
"document_with_boxes_image_path": document_with_boxes_relpath,
|
| 189 |
+
"document_markdown_text": doc.get("document_markdown_text") or "",
|
|
|
|
| 190 |
"figures": figure_entries,
|
| 191 |
+
"document_markdown_path": str(doc.get("document_path") or ""),
|
| 192 |
+
"document_final_markdown_path": str(doc.get("document_final_markdown_path") or ""),
|
| 193 |
+
"document_final_markdown_text": doc.get("document_final_markdown_text") or "",
|
| 194 |
+
"raw_response_path": str(doc.get("raw_response_path") or ""),
|
| 195 |
}
|
| 196 |
|
| 197 |
|
|
|
|
| 230 |
else:
|
| 231 |
data = dict(record)
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
yield data
|
| 234 |
|
| 235 |
write_jsonl_iter(dataset_path, _record_iterator())
|
|
|
|
| 257 |
record = json.loads(line)
|
| 258 |
if record.get("figures") is None:
|
| 259 |
record["figures"] = []
|
|
|
|
|
|
|
| 260 |
records.append(record)
|
| 261 |
return records
|
| 262 |
|