HowdenParser 5.2.2__tar.gz → 5.2.4__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.
@@ -1,7 +1,10 @@
1
1
  import os
2
+ import json
2
3
  import logging
3
4
  from pathlib import Path
4
5
  from ..parser import BaseParser
6
+ from typing import Any
7
+ from llama_parse import ResultType
5
8
 
6
9
  class LlamaParser(BaseParser, name="llamaparser"):
7
10
  def __init__(self, result_type: str, model: str, parse_mode: str, provider_and_model: str,
@@ -43,9 +46,15 @@ class LlamaParser(BaseParser, name="llamaparser"):
43
46
  if not api_key:
44
47
  raise EnvironmentError("Missing LLAMA-PARSER-API-TOKEN in .env file.")
45
48
 
46
- rt = self.result_type
47
- if rt.lower() in ("md", "markdown"):
49
+ rt_lower = str(self.result_type).lower()
50
+ if rt_lower in ("md","markdown"):
48
51
  rt = ResultType.MD
52
+ elif rt_lower in ("txt","text"):
53
+ rt = ResultType.TXT
54
+ elif rt_lower in ("json"):
55
+ rt = ResultType.JSON
56
+ else:
57
+ raise NotImplementedError(f"Result type {self.result_type} is not supported.")
49
58
 
50
59
  # Construct the parser INSIDE the worker thread
51
60
  self._parser = LlamaParse(
@@ -61,31 +70,26 @@ class LlamaParser(BaseParser, name="llamaparser"):
61
70
 
62
71
  logging.info("LlamaParser initialized inside worker thread")
63
72
 
64
- def parse(self, file_path: Path, include_pagenumbers: bool = False) -> str:
73
+ def parse(self, file_path: Path, include_pagenumbers: bool = False) -> Any:
65
74
  # Ensure parser is created inside the thread event loop
66
75
  self._lazy_init()
76
+ def page_break(text: str, idx: int) -> str:
77
+ return f"<PAGE_NUMBER {idx}>{text}</PAGE_NUMBER {idx}>"
67
78
 
68
- # Standard calls
69
- if not include_pagenumbers:
70
- documents = self._parser.load_data(str(file_path))
71
- return "\n".join(doc.text for doc in documents)
72
-
73
- # With page numbers
74
79
  documents = self._parser.parse(file_path)
75
-
76
- if self.result_type.lower() in ("md", "markdown"):
77
- return "\n".join(
78
- f"<PAGE_NUMBER {idx}>{page.md}</PAGE_NUMBER {idx}>"
79
- for idx, page in enumerate(documents.pages, start=1)
80
- )
81
-
82
- return "\n".join(
83
- f"<PAGE_NUMBER {idx}>{page.text}</PAGE_NUMBER {idx}>"
84
- for idx, page in enumerate(documents.pages, start=1)
85
- )
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.")
86
90
 
87
91
  def __call__(self, file_path: Path) -> str:
88
92
  return self.parse(file_path)
89
93
 
90
94
  def write_json_hyperparameter(self, folder_file_path: Path) -> None:
91
- self.write_parameters(self._input_params, folder_file_path)
95
+ self.write_parameters(self._input_params, folder_file_path)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HowdenParser
3
- Version: 5.2.2
3
+ Version: 5.2.4
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,7 @@ 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)
19
20
  Description-Content-Type: text/markdown
20
21
 
21
22
  # OCR & LLM Parser
@@ -1,41 +1,42 @@
1
- [project]
2
- name = "HowdenParser"
3
- version = "5.2.2"
4
- description = "A simple configuration manager with Pydantic and JSON export."
5
- readme = "README.md"
6
- requires-python = ">=3.12,<3.14"
7
- authors = [
8
- { name = "JesperThoftIllemannJ", email = "jesper.jaeger@howdendanmark.dk" },
9
- ]
10
- keywords = [
11
- "config",
12
- "configuration",
13
- "pydantic",
14
- "json",
15
- ]
16
- homepage = "https://github.com/yourusername/config"
17
- repository = "https://github.com/yourusername/config"
18
- documentation = "https://github.com/yourusername/config"
19
- dependencies = [
20
- "mistralai (>=1.9.3,<2.0.0)",
21
- "llama-parse (>=0.6.58,<0.7.0)",
22
- "pypdf2 (>=3.0.1,<4.0.0)",
23
- "pdf2image (>=1.17.0,<2.0.0)",
24
- "langchain (>=1.1.3,<2.0.0)",
25
- ]
26
-
27
- [project.license]
28
- text = "MIT"
29
-
30
- [build-system]
31
- requires = [
32
- "poetry-core>=2.0.0,<3.0.0",
33
- ]
34
- build-backend = "poetry.core.masonry.api"
35
-
36
- [dependency-groups]
37
- dev = [
38
- "toml (>=0.10.2,<0.11.0)",
39
- "tomli-w (>=1.2.0,<2.0.0)",
40
- "howdenconfig (>=1.0.6,<2.0.0)",
41
- ]
1
+ [project]
2
+ name = "HowdenParser"
3
+ version = "5.2.4"
4
+ description = "A simple configuration manager with Pydantic and JSON export."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12,<3.14"
7
+ authors = [
8
+ { name = "JesperThoftIllemannJ", email = "jesper.jaeger@howdendanmark.dk" },
9
+ ]
10
+ keywords = [
11
+ "config",
12
+ "configuration",
13
+ "pydantic",
14
+ "json",
15
+ ]
16
+ homepage = "https://github.com/yourusername/config"
17
+ repository = "https://github.com/yourusername/config"
18
+ documentation = "https://github.com/yourusername/config"
19
+ dependencies = [
20
+ "mistralai (>=1.9.3,<2.0.0)",
21
+ "llama-parse (>=0.6.58,<0.7.0)",
22
+ "pypdf2 (>=3.0.1,<4.0.0)",
23
+ "pdf2image (>=1.17.0,<2.0.0)",
24
+ "langchain (>=1.1.3,<2.0.0)",
25
+ "pytest (>=9.0.2,<10.0.0)",
26
+ ]
27
+
28
+ [project.license]
29
+ text = "MIT"
30
+
31
+ [build-system]
32
+ requires = [
33
+ "poetry-core>=2.0.0,<3.0.0",
34
+ ]
35
+ build-backend = "poetry.core.masonry.api"
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "toml (>=0.10.2,<0.11.0)",
40
+ "tomli-w (>=1.2.0,<2.0.0)",
41
+ "howdenconfig (>=1.0.6,<2.0.0)",
42
+ ]
File without changes