Florent Gbelidji commited on
Sync DeepSeek OCR HF job code
Browse files- ds_batch_ocr/config.py +2 -1
- ds_batch_ocr/stages.py +21 -9
ds_batch_ocr/config.py
CHANGED
|
@@ -32,7 +32,8 @@ class DocumentMetadata:
|
|
| 32 |
document_markdown_text: str
|
| 33 |
document_final_markdown_path: Optional[str] = None
|
| 34 |
document_final_markdown_text: Optional[str] = None
|
| 35 |
-
extracted_figures: List[
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
@dataclass
|
|
|
|
| 32 |
document_markdown_text: str
|
| 33 |
document_final_markdown_path: Optional[str] = None
|
| 34 |
document_final_markdown_text: Optional[str] = None
|
| 35 |
+
extracted_figures: List[str] = field(default_factory=list)
|
| 36 |
+
extracted_figures_metadata: List[FigureMetadata] = field(default_factory=list)
|
| 37 |
|
| 38 |
|
| 39 |
@dataclass
|
ds_batch_ocr/stages.py
CHANGED
|
@@ -312,21 +312,33 @@ def run_stage_extract(settings: ExtractSettings) -> None:
|
|
| 312 |
|
| 313 |
#write document with boxes image to file
|
| 314 |
img_draw.save(ctx["sample_dir"] / "document_with_boxes.png")
|
| 315 |
-
|
| 316 |
-
#build document metadata
|
| 317 |
doc_metadata = DocumentMetadata(
|
| 318 |
sample_id=ctx["sample_id"],
|
| 319 |
dataset_index=ctx["dataset_index"],
|
| 320 |
-
document_path=
|
| 321 |
-
raw_response_path=
|
| 322 |
-
source_image_path=
|
| 323 |
-
document_with_boxes_path=
|
| 324 |
document_markdown_text=markdown,
|
| 325 |
-
document_final_markdown_path="",
|
| 326 |
-
document_final_markdown_text="",
|
| 327 |
extracted_figures=figures,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
)
|
| 329 |
-
batch_document_dicts.append(dataclass_to_dict(doc_metadata))
|
| 330 |
|
| 331 |
LOGGER.debug(
|
| 332 |
"Processed sample %s | figures=%s | markdown_chars=%s",
|
|
|
|
| 312 |
|
| 313 |
#write document with boxes image to file
|
| 314 |
img_draw.save(ctx["sample_dir"] / "document_with_boxes.png")
|
| 315 |
+
|
|
|
|
| 316 |
doc_metadata = DocumentMetadata(
|
| 317 |
sample_id=ctx["sample_id"],
|
| 318 |
dataset_index=ctx["dataset_index"],
|
| 319 |
+
document_path=document_path,
|
| 320 |
+
raw_response_path=raw_response_path,
|
| 321 |
+
source_image_path=ctx["sample_dir"] / "source.png",
|
| 322 |
+
document_with_boxes_path=ctx["sample_dir"] / "document_with_boxes.png",
|
| 323 |
document_markdown_text=markdown,
|
|
|
|
|
|
|
| 324 |
extracted_figures=figures,
|
| 325 |
+
extracted_figures_metadata=figures_metadata,
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
#build document metadata
|
| 329 |
+
batch_document_dicts.append(
|
| 330 |
+
{
|
| 331 |
+
"sample_id": ctx["sample_id"],
|
| 332 |
+
"dataset_index": ctx["dataset_index"],
|
| 333 |
+
"document_path": document_path,
|
| 334 |
+
"raw_response_path": raw_response_path,
|
| 335 |
+
"source_image_path": ctx["sample_dir"] / "source.png",
|
| 336 |
+
"document_with_boxes_path": ctx["sample_dir"] / "document_with_boxes.png",
|
| 337 |
+
"document_markdown_text": markdown,
|
| 338 |
+
"extracted_figures": [figure.image_path for figure in figures],
|
| 339 |
+
"extracted_figures_metadata": [figure.to_dict() for figure in figures],
|
| 340 |
+
}
|
| 341 |
)
|
|
|
|
| 342 |
|
| 343 |
LOGGER.debug(
|
| 344 |
"Processed sample %s | figures=%s | markdown_chars=%s",
|