ocr-stream 1.3__tar.gz → 1.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,19 +1,32 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ocr_stream
3
- Version: 1.3
3
+ Version: 1.4
4
4
  Summary: Extrair textos de documentos digitalizados e imagens.
5
5
  Author: Bruno Chaves
6
+ Requires: PyPDF2
7
+ Requires: PyMuPDF
8
+ Requires: reportlab
9
+ Requires: openpyxl
10
+ Requires: openpyxl
11
+ Requires: pandas
12
+ Requires: Pillow
13
+ Requires: opencv_python
14
+ Requires: requests
15
+ Requires: pytesseract
16
+ Requires: soup_files
17
+ Requires: convert_stream
6
18
  Requires-Python: >=3.11
7
19
  Description-Content-Type: text/markdown
8
- Requires-Dist: PyPDF2
9
20
  Requires-Dist: PyMuPDF
10
21
  Requires-Dist: reportlab
11
22
  Requires-Dist: openpyxl
12
23
  Requires-Dist: pandas
13
24
  Requires-Dist: Pillow>=11.3.0
25
+ Requires-Dist: requests>=2.32.4
14
26
  Requires-Dist: opencv-python
15
- Requires-Dist: convert_stream
27
+ Requires-Dist: convert_stream>=1.4
16
28
  Requires-Dist: soup_files
29
+ Dynamic: requires
17
30
 
18
31
  # ocrlib
19
32
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
 
3
3
  from .models.m_modules_ocr import LibraryOCR
4
- from .modules_ocr import TextRecognized
4
+ from .modules_ocr import TextRecognized, BinaryTesseract
5
5
  from .utils import File, Directory, InputFiles, UserFileSystem
6
6
  from .extractors import RecognizeImage, RecognizePdf
7
7
  from ._version import __version__, __modify_data__
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+
4
+ __version__ = '1.4'
5
+ __modify_data__ = '2025-07-11'
@@ -2,13 +2,12 @@
2
2
  from __future__ import annotations
3
3
  from typing import List
4
4
  from ocr_stream.utils import (
5
- File, Directory, ImageObject,
6
- DataFrame, PageDocumentPdf,
7
- DocumentPdf, PdfStream, LibraryPDF,
5
+ File, ImageObject,
6
+ DataFrame, PageDocumentPdf, DocumentPdf,
8
7
  )
9
8
  from ocr_stream.models import LibraryOCR
10
9
  from ocr_stream.modules_ocr import ModuleOcr, TextRecognized, BinaryTesseract
11
- from convert_stream import LibImageToPDF, ConvertPdfToImage, CreatePbar
10
+ from convert_stream import ConvertPdfToImage, CreatePbar
12
11
  from soup_files import ProgressBarAdapter
13
12
 
14
13
 
@@ -2,7 +2,6 @@
2
2
  from __future__ import annotations
3
3
  from types import ModuleType
4
4
  from typing import List, Dict
5
- from pathlib import Path
6
5
  from shutil import which
7
6
  import re
8
7
  import os
@@ -15,8 +14,8 @@ from ocr_stream.models import (
15
14
 
16
15
  from ocr_stream.utils import (
17
16
  PageDocumentPdf, DocumentPdf, LibraryImage, LibraryPDF,
18
- ImageObject, ArrayString, DataString, File, Directory,
19
- FileToTable, ColumnTable, KERNEL_TYPE,
17
+ ImageObject, DataString, File, Directory,
18
+ ColumnTable, KERNEL_TYPE, ArrayString,
20
19
  )
21
20
 
22
21
  try:
@@ -37,7 +36,7 @@ class TextRecognizedToi(object):
37
36
  self.separator: str = separator
38
37
  self.file: File = file
39
38
  self.column_text: str = column_text
40
-
39
+ self.listText = []
41
40
  self.pattern_line_uc_toi = r'UC:\s*\d+\s*TOI:\s*\d+'
42
41
  self.pattern_uc = r'\b(?:UC:?|UC):?\s*(\d+)'
43
42
  self.pattern_toi = r'\b(?:TOI?|TO):?\s*(\d+)'
@@ -80,7 +79,11 @@ class TextRecognizedToi(object):
80
79
  return self.text_document.split(self.separator)
81
80
 
82
81
  def to_array_string(self) -> ArrayString:
83
- values: List[str] = self.to_list()
82
+ try:
83
+ return ArrayString(self.to_list())
84
+ except Exception as e:
85
+ print(e)
86
+ return ArrayString([])
84
87
 
85
88
  def to_upper(self) -> TextRecognizedToi:
86
89
  self.text_document = self.text_document.upper()
@@ -120,20 +123,21 @@ class TextRecognizedToi(object):
120
123
  self.listText = values
121
124
  return self
122
125
 
123
- def uc(self) -> str:
126
+ def uc(self) -> str | None:
124
127
  """
125
128
  Extrair o número da UC em forma de string, se a operação falhar, será retornado (nan)
126
129
  """
127
130
  line_uc_toi = self.line_uc_and_toi()
131
+
128
132
  uc_value: str = None
129
133
  if line_uc_toi is not None:
130
- uc_value = self.__get_match_group(self.pattern_uc, line_uc_toi)
134
+ uc_value: str = self.__get_match_group(self.pattern_uc, line_uc_toi.value)
131
135
  if uc_value is not None:
132
136
  return uc_value.replace('UC', '')
133
137
 
134
138
  arr = ArrayString(self.text_document.split(' '))
135
139
  for w in self.words_uc:
136
- out = arr.get_next(w).value
140
+ out: str = arr.get_next(w).value
137
141
  try:
138
142
  int(out)
139
143
  except:
@@ -142,11 +146,14 @@ class TextRecognizedToi(object):
142
146
  return out
143
147
  return None
144
148
 
145
- def toi(self) -> str:
149
+ def toi(self) -> str | None:
146
150
  line_uc_toi = self.line_uc_and_toi()
151
+ if line_uc_toi is None:
152
+ return None
153
+
147
154
  toi_value: str = None
148
155
  if line_uc_toi is not None:
149
- toi_value = self.__get_match_group(self.pattern_toi, line_uc_toi)
156
+ toi_value = self.__get_match_group(self.pattern_toi, line_uc_toi.value)
150
157
  if toi_value is not None:
151
158
  return toi_value.replace('TOI', '')
152
159
  arr = ArrayString(self.text_document.split(' '))
@@ -194,9 +201,8 @@ class TextRecognizedToi(object):
194
201
  def line_roteiro(self) -> DataString:
195
202
  return DataString(None)
196
203
 
197
- #======================================================================#
198
-
199
204
 
205
+ #======================================================================#
200
206
  # Texto reconhecido de uma imagem.
201
207
  #======================================================================#
202
208
 
@@ -269,6 +275,13 @@ class BinaryTesseract(object):
269
275
  disponível. Você pode usar um binário alternativo, basta informar
270
276
  o caminho do binário desejado no construtor.
271
277
  """
278
+ _instance = None # Atributo de classe para armazenar a instância singleton
279
+
280
+ def __new__(cls, *args, **kwargs):
281
+ if cls._instance is None:
282
+ cls._instance = super(BinaryTesseract, cls).__new__(cls)
283
+ return cls._instance
284
+
272
285
  def __init__(
273
286
  self,
274
287
  path: File = None, *,
@@ -276,6 +289,11 @@ class BinaryTesseract(object):
276
289
  tess_data_dir: Directory = None
277
290
  ):
278
291
  #
292
+ # Garante que __init__ não será executado mais de uma vez
293
+ if hasattr(self, '_initialized') and self._initialized:
294
+ return
295
+ self._initialized = True
296
+
279
297
  self.tess_data_dir: Directory = tess_data_dir
280
298
  self.lang: str = lang
281
299
  self.path_tesseract: File = path
@@ -291,9 +309,10 @@ class BinaryTesseract(object):
291
309
  self.path_tesseract = File(output)
292
310
 
293
311
  def exists(self) -> bool:
312
+ """Verifica se o binário tesseract existe"""
294
313
  if self.path_tesseract is None:
295
314
  return False
296
- return True
315
+ return self.path_tesseract.exists()
297
316
 
298
317
 
299
318
  #======================================================================#
@@ -1,19 +1,32 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ocr_stream
3
- Version: 1.3
3
+ Version: 1.4
4
4
  Summary: Extrair textos de documentos digitalizados e imagens.
5
5
  Author: Bruno Chaves
6
+ Requires: PyPDF2
7
+ Requires: PyMuPDF
8
+ Requires: reportlab
9
+ Requires: openpyxl
10
+ Requires: openpyxl
11
+ Requires: pandas
12
+ Requires: Pillow
13
+ Requires: opencv_python
14
+ Requires: requests
15
+ Requires: pytesseract
16
+ Requires: soup_files
17
+ Requires: convert_stream
6
18
  Requires-Python: >=3.11
7
19
  Description-Content-Type: text/markdown
8
- Requires-Dist: PyPDF2
9
20
  Requires-Dist: PyMuPDF
10
21
  Requires-Dist: reportlab
11
22
  Requires-Dist: openpyxl
12
23
  Requires-Dist: pandas
13
24
  Requires-Dist: Pillow>=11.3.0
25
+ Requires-Dist: requests>=2.32.4
14
26
  Requires-Dist: opencv-python
15
- Requires-Dist: convert_stream
27
+ Requires-Dist: convert_stream>=1.4
16
28
  Requires-Dist: soup_files
29
+ Dynamic: requires
17
30
 
18
31
  # ocrlib
19
32
 
@@ -1,5 +1,6 @@
1
1
  README.md
2
2
  pyproject.toml
3
+ setup.py
3
4
  ocr_stream/__init__.py
4
5
  ocr_stream/__main__.py
5
6
  ocr_stream/_version.py
@@ -8,6 +9,7 @@ ocr_stream/modules_ocr.py
8
9
  ocr_stream.egg-info/PKG-INFO
9
10
  ocr_stream.egg-info/SOURCES.txt
10
11
  ocr_stream.egg-info/dependency_links.txt
12
+ ocr_stream.egg-info/not-zip-safe
11
13
  ocr_stream.egg-info/requires.txt
12
14
  ocr_stream.egg-info/top_level.txt
13
15
  ocr_stream/models/__init__.py
@@ -1,9 +1,9 @@
1
- PyPDF2
2
1
  PyMuPDF
3
2
  reportlab
4
3
  openpyxl
5
4
  pandas
6
5
  Pillow>=11.3.0
6
+ requests>=2.32.4
7
7
  opencv-python
8
- convert_stream
8
+ convert_stream>=1.4
9
9
  soup_files
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ocr_stream"
7
- version = "1.3"
7
+ version = "1.4"
8
8
  authors = [
9
9
  { name="Bruno Chaves"},
10
10
  ]
@@ -14,14 +14,14 @@ readme = "README.md"
14
14
  requires-python = ">=3.11"
15
15
 
16
16
  dependencies = [
17
- "PyPDF2",
18
17
  "PyMuPDF",
19
18
  "reportlab",
20
19
  "openpyxl",
21
20
  "pandas",
22
21
  "Pillow>=11.3.0",
22
+ "requests>=2.32.4",
23
23
  "opencv-python",
24
- "convert_stream",
24
+ "convert_stream>=1.4",
25
25
  "soup_files",
26
26
  ]
27
27
 
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import os
4
+ import sys
5
+
6
+ try:
7
+ from setuptools import setup
8
+ except Exception as e:
9
+ print(e)
10
+ sys.exit(1)
11
+
12
+ file_setup = os.path.abspath(os.path.realpath(__file__))
13
+ dir_of_project = os.path.dirname(file_setup)
14
+ sys.path.insert(0, dir_of_project)
15
+
16
+
17
+ DESCRIPTION = ''
18
+ LONG_DESCRIPTION = ''
19
+
20
+ setup(
21
+ name='ocrlib',
22
+ version='1.2',
23
+ description=DESCRIPTION,
24
+ long_description=LONG_DESCRIPTION,
25
+ license='MIT',
26
+ requires=[
27
+ 'PyPDF2',
28
+ 'PyMuPDF',
29
+ 'reportlab',
30
+ 'openpyxl',
31
+ 'openpyxl',
32
+ 'pandas',
33
+ 'Pillow',
34
+ 'opencv_python',
35
+ 'requests',
36
+ 'pytesseract',
37
+ 'soup_files',
38
+ 'convert_stream',
39
+ ],
40
+ packages=['ocrlib', 'ocrlib.models', 'ocrlib.utils'],
41
+ zip_safe=False,
42
+ )
43
+
44
+
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env python3
2
- #
3
-
4
- __version__ = '1.3'
5
- __modify_data__ = '2025-07-06'
File without changes
File without changes