-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8803e2
commit 8067f19
Showing
11 changed files
with
1,663 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
uv-install-python:: | ||
uv python install | ||
uv-update-lock-file: | ||
uv lock | ||
uv-install-dependencies: | ||
uv sync --dev | ||
|
||
uv-run-dev: | ||
uv run poe dev | ||
uv-run-test: | ||
uv run poe test | ||
uv-run-test-coverage: | ||
uv run poe test-coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[project] | ||
name = "hm-docling" | ||
version = "1.0.0" | ||
requires-python = "~=3.12.0" | ||
dependencies = [ | ||
"docling==2.14.0", | ||
] | ||
|
||
[dependency-groups] | ||
dev = [ | ||
"poethepoet==0.31.1", | ||
"pytest==8.3.4", | ||
"pytest-cov==6.0.0", | ||
] | ||
|
||
[tool.uv] | ||
package = false | ||
|
||
[[tool.uv.index]] | ||
name = "pytorch-cu124" | ||
url = "https://download.pytorch.org/whl/cu124" | ||
explicit = true | ||
|
||
[tool.poe.tasks] | ||
dev = "python src/main.py" | ||
test = "pytest --verbose --verbose" | ||
test-coverage = "pytest --cov=. --cov-report=xml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class TestDummy: | ||
def test_dummy(self): | ||
assert 1 + 1 == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
from docling.datamodel.pipeline_options import EasyOcrOptions, PdfPipelineOptions | ||
from docling.document_converter import DocumentConverter | ||
|
||
|
||
def main() -> None: | ||
data_dir = Path("data") | ||
pdf_paths = data_dir.glob("**/*.pdf") | ||
|
||
pipeline_options = PdfPipelineOptions() | ||
pipeline_options.do_ocr = True | ||
pipeline_options.do_table_structure = True | ||
pipeline_options.table_structure_options.do_cell_matching = True | ||
pipeline_options.ocr_options = EasyOcrOptions(force_full_page_ocr=True) | ||
|
||
converter = DocumentConverter() | ||
|
||
for pdf_path in pdf_paths: | ||
try: | ||
# Convert PDF to markdown | ||
res = converter.convert(pdf_path) | ||
markdown_content = res.document.export_to_markdown() | ||
|
||
# Write markdown to file | ||
markdown_path = pdf_path.with_suffix(".md") | ||
markdown_path.write_text(markdown_content, encoding="utf-8") | ||
logging.info(f"Converted {pdf_path.name}") | ||
except Exception as e: | ||
logging.info(f"Error processing {pdf_path.name}: {e}") | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(level=logging.INFO) | ||
main() |
Oops, something went wrong.