HowdenParser 2.0.1__tar.gz → 2.0.3__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-2.0.1 → howdenparser-2.0.3}/HowdenParser/parameter/llamaparser.py +0 -4
- {howdenparser-2.0.1 → howdenparser-2.0.3}/HowdenParser/parser.py +20 -4
- {howdenparser-2.0.1 → howdenparser-2.0.3}/PKG-INFO +1 -1
- {howdenparser-2.0.1 → howdenparser-2.0.3}/pyproject.toml +1 -1
- {howdenparser-2.0.1 → howdenparser-2.0.3}/HowdenParser/__init__.py +0 -0
- {howdenparser-2.0.1 → howdenparser-2.0.3}/HowdenParser/parameter/__init__.py +0 -0
- {howdenparser-2.0.1 → howdenparser-2.0.3}/HowdenParser/parameter/huggingface.py +0 -0
- {howdenparser-2.0.1 → howdenparser-2.0.3}/HowdenParser/parameter/mistralocr.py +0 -0
- {howdenparser-2.0.1 → howdenparser-2.0.3}/README.md +0 -0
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
from typing import Literal
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
5
|
-
class Hest(BaseModel):
|
|
6
|
-
provider_and_model: str = "huggingface:trocr-large-printed"
|
|
7
|
-
|
|
8
5
|
|
|
9
6
|
class Parameter(BaseModel):
|
|
10
|
-
model1: Hest = Hest()
|
|
11
7
|
provider_and_model: str = "llamaparser:"
|
|
12
8
|
result_type: Literal["md"] = "md"
|
|
13
9
|
mode: bool = False
|
|
@@ -126,6 +126,10 @@ class MistralOCRParser(BaseParser, name="mistralocr"):
|
|
|
126
126
|
|
|
127
127
|
return "\n".join(doc.markdown for doc in ocr_response.pages)
|
|
128
128
|
|
|
129
|
+
def __call__(self, file_path: Path) -> str:
|
|
130
|
+
# When instance is called, it delegates to parse
|
|
131
|
+
return self.parse(file_path)
|
|
132
|
+
|
|
129
133
|
@staticmethod
|
|
130
134
|
def _count_pages(file_path: Path) -> int:
|
|
131
135
|
reader = PdfReader(str(file_path))
|
|
@@ -142,26 +146,38 @@ class LangChainParser(BaseParser, name="langchain"):
|
|
|
142
146
|
response = self.model(text)
|
|
143
147
|
return {"source": "LangChain", "output": response}
|
|
144
148
|
|
|
149
|
+
def __call__(self, file_path: Path) -> str:
|
|
150
|
+
# When instance is called, it delegates to parse
|
|
151
|
+
return self.parse(file_path)
|
|
152
|
+
|
|
145
153
|
|
|
146
154
|
class LlamaParser(BaseParser, name="llamaparser"):
|
|
147
|
-
def __init__(self, result_type: str, mode: bool) -> None:
|
|
155
|
+
def __init__(self, result_type: str, mode: bool, provider_and_model) -> None:
|
|
148
156
|
logging.info("Initializing LlamaParser...")
|
|
149
157
|
|
|
158
|
+
self.result_type = result_type
|
|
159
|
+
self.mode = mode
|
|
160
|
+
self.provider_and_model = provider_and_model
|
|
161
|
+
|
|
150
162
|
from llama_parse import LlamaParse, ResultType
|
|
151
163
|
|
|
152
164
|
if result_type.lower() in ("md", "markdown"):
|
|
153
|
-
|
|
165
|
+
result_type = ResultType.MD
|
|
154
166
|
|
|
155
167
|
api_key = os.getenv("LLAMA-PARSER-API-TOKEN")
|
|
156
168
|
if not api_key:
|
|
157
169
|
raise EnvironmentError("Missing LLAMA-PARSER-API-TOKEN in .env file.")
|
|
158
170
|
|
|
159
|
-
self.
|
|
171
|
+
self._parser = LlamaParse(api_key=api_key, result_type=result_type, premium_mode=self.mode)
|
|
160
172
|
|
|
161
173
|
def parse(self, file_path: Path) -> str:
|
|
162
|
-
documents = self.
|
|
174
|
+
documents = self._parser.load_data(str(file_path))
|
|
163
175
|
return "\n".join(doc.text for doc in documents)
|
|
164
176
|
|
|
177
|
+
def __call__(self, file_path: Path) -> str:
|
|
178
|
+
# When instance is called, it delegates to parse
|
|
179
|
+
return self.parse(file_path)
|
|
180
|
+
|
|
165
181
|
|
|
166
182
|
class HuggingFaceParser(BaseParser, name="huggingface"):
|
|
167
183
|
def __init__(self, provider_and_model: str) -> None:
|
|
@@ -14,7 +14,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
14
14
|
|
|
15
15
|
[tool.poetry]
|
|
16
16
|
name = "HowdenParser"
|
|
17
|
-
version = "2.0.
|
|
17
|
+
version = "2.0.3"
|
|
18
18
|
description = "A simple configuration manager with Pydantic and JSON export."
|
|
19
19
|
authors = [ "JesperThoftIllemannJ <jesper.jaeger@howdendanmark.dk>",]
|
|
20
20
|
readme = "README.md"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|