HowdenParser 5.2.3__tar.gz → 5.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parsers/llama_parser.py +20 -25
- {howdenparser-5.2.3 → howdenparser-5.2.5}/PKG-INFO +3 -1
- {howdenparser-5.2.3 → howdenparser-5.2.5}/pyproject.toml +3 -1
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/__init__.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parameter/__init__.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parameter/llamaparser.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parameter/mistralocr.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parser.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parsers/__init__.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parsers/langchain_parser.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/HowdenParser/parsers/mistral_parser.py +0 -0
- {howdenparser-5.2.3 → howdenparser-5.2.5}/README.md +0 -0
|
@@ -4,6 +4,7 @@ import logging
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from ..parser import BaseParser
|
|
6
6
|
from typing import Any
|
|
7
|
+
from llama_parse import ResultType
|
|
7
8
|
|
|
8
9
|
class LlamaParser(BaseParser, name="llamaparser"):
|
|
9
10
|
def __init__(self, result_type: str, model: str, parse_mode: str, provider_and_model: str,
|
|
@@ -45,13 +46,15 @@ class LlamaParser(BaseParser, name="llamaparser"):
|
|
|
45
46
|
if not api_key:
|
|
46
47
|
raise EnvironmentError("Missing LLAMA-PARSER-API-TOKEN in .env file.")
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
rt_lower = str(rt).lower()
|
|
51
|
-
if rt_lower in ("md", "markdown"):
|
|
49
|
+
rt_lower = str(self.result_type).lower()
|
|
50
|
+
if rt_lower in ("md","markdown"):
|
|
52
51
|
rt = ResultType.MD
|
|
53
|
-
elif rt_lower in ("
|
|
52
|
+
elif rt_lower in ("txt","text"):
|
|
53
|
+
rt = ResultType.TXT
|
|
54
|
+
elif rt_lower in ("json"):
|
|
54
55
|
rt = ResultType.JSON
|
|
56
|
+
else:
|
|
57
|
+
raise NotImplementedError(f"Result type {self.result_type} is not supported.")
|
|
55
58
|
|
|
56
59
|
# Construct the parser INSIDE the worker thread
|
|
57
60
|
self._parser = LlamaParse(
|
|
@@ -70,28 +73,20 @@ class LlamaParser(BaseParser, name="llamaparser"):
|
|
|
70
73
|
def parse(self, file_path: Path, include_pagenumbers: bool = False) -> Any:
|
|
71
74
|
# Ensure parser is created inside the thread event loop
|
|
72
75
|
self._lazy_init()
|
|
76
|
+
def page_break(text: str, idx: int) -> str:
|
|
77
|
+
return f"<PAGE_NUMBER {idx}>{text}</PAGE_NUMBER {idx}>"
|
|
73
78
|
|
|
74
|
-
# Standard calls
|
|
75
|
-
if not include_pagenumbers:
|
|
76
|
-
documents = self._parser.load_data(str(file_path))
|
|
77
|
-
return "\n".join(doc.text for doc in documents)
|
|
78
|
-
|
|
79
|
-
# With page numbers
|
|
80
79
|
documents = self._parser.parse(file_path)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return "\n".join(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return "\n".join(
|
|
92
|
-
f"<PAGE_NUMBER {idx}>{page.text}</PAGE_NUMBER {idx}>"
|
|
93
|
-
for idx, page in enumerate(documents.pages, start=1)
|
|
94
|
-
)
|
|
80
|
+
if self.result_type in ['md','markdown']:
|
|
81
|
+
if include_pagenumbers: return "\n".join(page_break(page.md, idx) for idx, page in enumerate(documents.pages, start=1))
|
|
82
|
+
else: return "\n".join(page.md for page in documents.pages)
|
|
83
|
+
elif self.result_type in ['txt','text']:
|
|
84
|
+
if include_pagenumbers: return "\n".join(page_break(page.text, idx) for idx, page in enumerate(documents.pages, start=1))
|
|
85
|
+
else: return "\n".join(page.text for page in documents.pages)
|
|
86
|
+
elif self.result_type.lower() == 'json':
|
|
87
|
+
return documents.model_dump()
|
|
88
|
+
else:
|
|
89
|
+
raise NotImplementedError(f"Result type {self.result_type} is not supported.")
|
|
95
90
|
|
|
96
91
|
def __call__(self, file_path: Path) -> str:
|
|
97
92
|
return self.parse(file_path)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: HowdenParser
|
|
3
|
-
Version: 5.2.
|
|
3
|
+
Version: 5.2.5
|
|
4
4
|
Summary: A simple configuration manager with Pydantic and JSON export.
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: config,configuration,pydantic,json
|
|
@@ -16,6 +16,8 @@ Requires-Dist: llama-parse (>=0.6.58,<0.7.0)
|
|
|
16
16
|
Requires-Dist: mistralai (>=1.9.3,<2.0.0)
|
|
17
17
|
Requires-Dist: pdf2image (>=1.17.0,<2.0.0)
|
|
18
18
|
Requires-Dist: pypdf2 (>=3.0.1,<4.0.0)
|
|
19
|
+
Requires-Dist: pytest (>=9.0.2,<10.0.0)
|
|
20
|
+
Requires-Dist: tomli-w (>=1.2.0,<2.0.0)
|
|
19
21
|
Description-Content-Type: text/markdown
|
|
20
22
|
|
|
21
23
|
# OCR & LLM Parser
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "HowdenParser"
|
|
3
|
-
version = "5.2.
|
|
3
|
+
version = "5.2.5"
|
|
4
4
|
description = "A simple configuration manager with Pydantic and JSON export."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12,<3.14"
|
|
@@ -22,6 +22,8 @@ dependencies = [
|
|
|
22
22
|
"pypdf2 (>=3.0.1,<4.0.0)",
|
|
23
23
|
"pdf2image (>=1.17.0,<2.0.0)",
|
|
24
24
|
"langchain (>=1.1.3,<2.0.0)",
|
|
25
|
+
"pytest (>=9.0.2,<10.0.0)",
|
|
26
|
+
"tomli-w (>=1.2.0,<2.0.0)",
|
|
25
27
|
]
|
|
26
28
|
|
|
27
29
|
[project.license]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|