doc-page-extractor 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.

Potentially problematic release.


This version of doc-page-extractor might be problematic. Click here for more details.

@@ -2,6 +2,7 @@ from .extractor import DocExtractor
2
2
  from .clipper import clip, clip_from_image
3
3
  from .plot import plot
4
4
  from .rectangle import Point, Rectangle
5
+ from .model import Model, HuggingfaceModel
5
6
  from .types import (
6
7
  ExtractedResult,
7
8
  OCRFragment,
@@ -52,6 +52,13 @@ class DocExtractor:
52
52
  self._latex: LaTeX = LaTeX(device, model)
53
53
  self._layout_order: LayoutOrder = LayoutOrder(device, model)
54
54
 
55
+ def prepare_models(self):
56
+ self._model.get_onnx_ocr_path()
57
+ self._model.get_yolo_path()
58
+ self._model.get_layoutreader_path()
59
+ self._model.get_struct_eqtable_path()
60
+ self._model.get_latex_path()
61
+
55
62
  def extract(
56
63
  self,
57
64
  image: Image,
@@ -31,9 +31,10 @@ class HuggingfaceModel(Model):
31
31
  def get_onnx_ocr_path(self) -> Path:
32
32
  return self._get_model_path(
33
33
  repo_id="moskize/OnnxOCR",
34
- filename=None,
34
+ filename="README.md",
35
35
  repo_type=None,
36
- is_snapshot=True
36
+ is_snapshot=True,
37
+ wanna_dir_path=True,
37
38
  )
38
39
 
39
40
  def get_yolo_path(self) -> Path:
@@ -42,14 +43,16 @@ class HuggingfaceModel(Model):
42
43
  filename="models/Layout/YOLO/doclayout_yolo_ft.pt",
43
44
  repo_type=None,
44
45
  is_snapshot=False,
46
+ wanna_dir_path=False,
45
47
  )
46
48
 
47
49
  def get_layoutreader_path(self) -> Path:
48
50
  return self._get_model_path(
49
51
  repo_id="hantian/layoutreader",
50
- filename=None,
52
+ filename="model.safetensors",
51
53
  repo_type=None,
52
54
  is_snapshot=True,
55
+ wanna_dir_path=True,
53
56
  )
54
57
 
55
58
  def get_struct_eqtable_path(self) -> Path:
@@ -58,6 +61,7 @@ class HuggingfaceModel(Model):
58
61
  filename="model.safetensors",
59
62
  repo_type=None,
60
63
  is_snapshot=True,
64
+ wanna_dir_path=True,
61
65
  )
62
66
 
63
67
  def get_latex_path(self) -> Path:
@@ -66,38 +70,45 @@ class HuggingfaceModel(Model):
66
70
  filename="checkpoints/weights.pth",
67
71
  repo_type="space",
68
72
  is_snapshot=True,
73
+ wanna_dir_path=True,
69
74
  )
70
75
 
71
76
  def _get_model_path(
72
77
  self,
73
78
  repo_id: str,
74
- filename: str | None,
79
+ filename: str,
75
80
  repo_type: str | None,
76
81
  is_snapshot: bool,
82
+ wanna_dir_path: bool,
77
83
  ) -> Path:
84
+
78
85
  with self._lock:
79
- cache_filename = "README.md"
80
- if filename is not None:
81
- cache_filename = filename
82
86
  model_path = try_to_load_from_cache(
83
87
  repo_id=repo_id,
84
- filename=cache_filename,
88
+ filename=filename,
85
89
  repo_type=repo_type,
86
90
  cache_dir=self._model_cache_dir
87
91
  )
88
92
  if isinstance(model_path, str):
89
- if filename is None:
90
- model_path = Path(model_path).parent
91
-
92
- elif is_snapshot:
93
- model_path = snapshot_download(
94
- cache_dir=self._model_cache_dir,
95
- repo_id=repo_id,
96
- )
93
+ model_path = Path(model_path)
94
+ if wanna_dir_path:
95
+ for _ in Path(filename).parts:
96
+ model_path = model_path.parent
97
+
97
98
  else:
98
- model_path = hf_hub_download(
99
- cache_dir=self._model_cache_dir,
100
- repo_id=repo_id,
101
- filename=filename,
102
- )
103
- return Path(model_path)
99
+ if is_snapshot:
100
+ model_path = snapshot_download(
101
+ cache_dir=self._model_cache_dir,
102
+ repo_id=repo_id,
103
+ repo_type=repo_type,
104
+ )
105
+ else:
106
+ model_path = hf_hub_download(
107
+ cache_dir=self._model_cache_dir,
108
+ repo_id=repo_id,
109
+ repo_type=repo_type,
110
+ filename=filename,
111
+ )
112
+ model_path = Path(model_path)
113
+
114
+ return model_path
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: doc-page-extractor
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: doc page extractor can identify text and format in images and return structured data.
5
5
  Home-page: https://github.com/Moskize91/doc-page-extractor
6
6
  Author: Tao Zeyu
@@ -1,11 +1,11 @@
1
- doc_page_extractor/__init__.py,sha256=Q3cZxT1wpjb1kGI0fJ9YvL4Fh_rBN3NdLqaZh4ATFQM,312
1
+ doc_page_extractor/__init__.py,sha256=rt_XALcqNNg3iVkMTUHltWxvdweH2FY6Y_olU2TkVBY,355
2
2
  doc_page_extractor/clipper.py,sha256=5S1TI0aqMebwlPv_Ih4Nxpp6MchEjOih-CiZfMWUAhI,3201
3
3
  doc_page_extractor/downloader.py,sha256=NbGN9ARnER8-gd4T1uc3W98WMEClVxMrqnShq8HibTw,455
4
- doc_page_extractor/extractor.py,sha256=SGDPEIjmp5HiAYq_nSVsKFTt0IvqJJXXDZRfFFRlfzU,6993
4
+ doc_page_extractor/extractor.py,sha256=7dJ1N4d2_9tB49XAfKBIJjEUvNtjf0CGqcm2uf6BMPg,7205
5
5
  doc_page_extractor/latex.py,sha256=kD3NIzZTEGUFIAqqyHYmNcfyTrlu77GB1YSFgzbFb7A,1024
6
6
  doc_page_extractor/layout_order.py,sha256=lm_rXzRZ3AtufaRwxqZPfM9vplwaOlE2pnTNc7Z_oLM,7435
7
7
  doc_page_extractor/layoutreader.py,sha256=BdC4oPbtpXoLmYhjuSFrKn6SNoT2zWw_gi95sGAUwrk,4031
8
- doc_page_extractor/model.py,sha256=BBrsY2iQXCIsvqemjL37pKRPV3EtKkXsl7yA5_SI8RE,2610
8
+ doc_page_extractor/model.py,sha256=yQhLz28rQ0aCHKs1AQgKdUIT9UkJtpA0HP2cpWN-rls,2891
9
9
  doc_page_extractor/ocr.py,sha256=niZY4ZgbbbV-IeTrtF3Y8LPPrynU2wvZKRVYbBP1Dog,5586
10
10
  doc_page_extractor/ocr_corrector.py,sha256=RfRA1jESEuqC8_a2kUEvHblT_B4xBjE0OApLMl1JiRg,3917
11
11
  doc_page_extractor/overlap.py,sha256=z1DF4_2OPvauDHwmz1SC1WosULkE84HKaRfNEgexPzc,5337
@@ -36,10 +36,10 @@ doc_page_extractor/struct_eqtable/internvl/internvl_lmdeploy.py,sha256=ACHxFntxS
36
36
  doc_page_extractor/struct_eqtable/pix2s/__init__.py,sha256=cXRo4eg6u1-TXktZ8rQf0HIzLmmScIwYQhbxMKl-MyA,76
37
37
  doc_page_extractor/struct_eqtable/pix2s/pix2s.py,sha256=fCNve8PNeJ3-AWJIhSeGtp-mYKoMXfW0CIpszkQnAaA,2535
38
38
  doc_page_extractor/struct_eqtable/pix2s/pix2s_trt.py,sha256=zSGw45JhWdZ3iuJel5Chsy-NzsOHx9QyPQIUAzzCjFE,43880
39
- doc_page_extractor-0.2.1.dist-info/licenses/LICENSE,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
39
+ doc_page_extractor-0.2.2.dist-info/licenses/LICENSE,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
40
40
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  tests/test_history_bus.py,sha256=g-bpDIiebyEHKDH0YS5OHF2ONfhZt3-EFLZhWJn94WE,2534
42
- doc_page_extractor-0.2.1.dist-info/METADATA,sha256=lAM7CCs34AN2TPf9dvNQQZu2EsGFVLMXPKqSaRddZQQ,2480
43
- doc_page_extractor-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
44
- doc_page_extractor-0.2.1.dist-info/top_level.txt,sha256=ErNybD_lBzAmw8mVBAK4htsAH_hp14jioZVex-tUqvM,25
45
- doc_page_extractor-0.2.1.dist-info/RECORD,,
42
+ doc_page_extractor-0.2.2.dist-info/METADATA,sha256=SATSntedRznSoTzLUsKWBHNwiD3CDujgc9FEvK_Fbg4,2480
43
+ doc_page_extractor-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
44
+ doc_page_extractor-0.2.2.dist-info/top_level.txt,sha256=ErNybD_lBzAmw8mVBAK4htsAH_hp14jioZVex-tUqvM,25
45
+ doc_page_extractor-0.2.2.dist-info/RECORD,,