yomitoku-client 0.0.1__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.
Files changed (50) hide show
  1. yomitoku_client-0.0.1/LICENSE +201 -0
  2. yomitoku_client-0.0.1/PKG-INFO +274 -0
  3. yomitoku_client-0.0.1/README.md +218 -0
  4. yomitoku_client-0.0.1/pyproject.toml +134 -0
  5. yomitoku_client-0.0.1/setup.cfg +4 -0
  6. yomitoku_client-0.0.1/src/yomitoku_client/__init__.py +69 -0
  7. yomitoku_client-0.0.1/src/yomitoku_client/cli.py +54 -0
  8. yomitoku_client-0.0.1/src/yomitoku_client/client.py +165 -0
  9. yomitoku_client-0.0.1/src/yomitoku_client/constants.py +39 -0
  10. yomitoku_client-0.0.1/src/yomitoku_client/exceptions.py +28 -0
  11. yomitoku_client-0.0.1/src/yomitoku_client/font_manager.py +60 -0
  12. yomitoku_client-0.0.1/src/yomitoku_client/formatters/__init__.py +17 -0
  13. yomitoku_client-0.0.1/src/yomitoku_client/parsers/__init__.py +7 -0
  14. yomitoku_client-0.0.1/src/yomitoku_client/parsers/sagemaker_parser.py +1114 -0
  15. yomitoku_client-0.0.1/src/yomitoku_client/pdf_generator.py +327 -0
  16. yomitoku_client-0.0.1/src/yomitoku_client/renderers/__init__.py +19 -0
  17. yomitoku_client-0.0.1/src/yomitoku_client/renderers/base.py +63 -0
  18. yomitoku_client-0.0.1/src/yomitoku_client/renderers/csv_renderer.py +180 -0
  19. yomitoku_client-0.0.1/src/yomitoku_client/renderers/factory.py +88 -0
  20. yomitoku_client-0.0.1/src/yomitoku_client/renderers/html_renderer.py +373 -0
  21. yomitoku_client-0.0.1/src/yomitoku_client/renderers/json_renderer.py +80 -0
  22. yomitoku_client-0.0.1/src/yomitoku_client/renderers/markdown_renderer.py +379 -0
  23. yomitoku_client-0.0.1/src/yomitoku_client/renderers/pdf_renderer.py +105 -0
  24. yomitoku_client-0.0.1/src/yomitoku_client/renderers/searchable_pdf.py +448 -0
  25. yomitoku_client-0.0.1/src/yomitoku_client/resource/MPLUS1p-Medium.ttf +0 -0
  26. yomitoku_client-0.0.1/src/yomitoku_client/resource/charset.txt +1 -0
  27. yomitoku_client-0.0.1/src/yomitoku_client/samples/__init__.py +76 -0
  28. yomitoku_client-0.0.1/src/yomitoku_client/samples/image.png +0 -0
  29. yomitoku_client-0.0.1/src/yomitoku_client/samples/image_sample.json +5687 -0
  30. yomitoku_client-0.0.1/src/yomitoku_client/samples/image_sample.png +0 -0
  31. yomitoku_client-0.0.1/src/yomitoku_client/samples/pdf.pdf +0 -0
  32. yomitoku_client-0.0.1/src/yomitoku_client/samples/pdf_sample.json +32136 -0
  33. yomitoku_client-0.0.1/src/yomitoku_client/samples/pdf_sample.pdf +0 -0
  34. yomitoku_client-0.0.1/src/yomitoku_client/samples.py +14181 -0
  35. yomitoku_client-0.0.1/src/yomitoku_client/utils.py +468 -0
  36. yomitoku_client-0.0.1/src/yomitoku_client/visualizers/__init__.py +13 -0
  37. yomitoku_client-0.0.1/src/yomitoku_client/visualizers/base.py +41 -0
  38. yomitoku_client-0.0.1/src/yomitoku_client/visualizers/document_visualizer.py +1503 -0
  39. yomitoku_client-0.0.1/src/yomitoku_client/visualizers/table_exporter.py +282 -0
  40. yomitoku_client-0.0.1/src/yomitoku_client.egg-info/PKG-INFO +274 -0
  41. yomitoku_client-0.0.1/src/yomitoku_client.egg-info/SOURCES.txt +48 -0
  42. yomitoku_client-0.0.1/src/yomitoku_client.egg-info/dependency_links.txt +1 -0
  43. yomitoku_client-0.0.1/src/yomitoku_client.egg-info/entry_points.txt +2 -0
  44. yomitoku_client-0.0.1/src/yomitoku_client.egg-info/requires.txt +49 -0
  45. yomitoku_client-0.0.1/src/yomitoku_client.egg-info/top_level.txt +1 -0
  46. yomitoku_client-0.0.1/tests/test_basic_functionality.py +385 -0
  47. yomitoku_client-0.0.1/tests/test_client.py +274 -0
  48. yomitoku_client-0.0.1/tests/test_enhanced_features.py +420 -0
  49. yomitoku_client-0.0.1/tests/test_exceptions.py +180 -0
  50. yomitoku_client-0.0.1/tests/test_parsers.py +471 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,274 @@
1
+ Metadata-Version: 2.4
2
+ Name: yomitoku-client
3
+ Version: 0.0.1
4
+ Summary: Yomitoku Client is a Python library for processing SageMaker Yomitoku API outputs with format conversion and visualization capabilities.
5
+ Author-email: Yomitoku Team <support-aws-marketplace@mlism.com>
6
+ License-Expression: Apache-2.0
7
+ Keywords: yomitoku,sagemaker,document-analysis,format-conversion,visualization
8
+ Requires-Python: <3.13,>=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pandas<2.3.0,>=2.0.0
12
+ Requires-Dist: numpy<2.0.0,>=1.24.0
13
+ Requires-Dist: matplotlib>=3.6.0
14
+ Requires-Dist: plotly>=5.13.0
15
+ Requires-Dist: streamlit>=1.22.0
16
+ Requires-Dist: pydantic>=2.9.2
17
+ Requires-Dist: aiohttp>=3.8.0
18
+ Requires-Dist: requests>=2.28.0
19
+ Requires-Dist: python-dotenv>=0.21.0
20
+ Requires-Dist: click>=8.1.0
21
+ Requires-Dist: lxml>=5.3.0
22
+ Requires-Dist: openpyxl>=3.0.10
23
+ Requires-Dist: python-docx>=0.8.11
24
+ Requires-Dist: PyPDF2>=3.0.0
25
+ Requires-Dist: pypdfium2>=4.30.0
26
+ Requires-Dist: pyarrow>=12.0.0
27
+ Requires-Dist: opencv-python>=4.8.0
28
+ Requires-Dist: Pillow>=9.5.0
29
+ Requires-Dist: seaborn>=0.12.0
30
+ Requires-Dist: reportlab>=4.4.1
31
+ Requires-Dist: jaconv>=0.4.0
32
+ Requires-Dist: boto3>=1.26.0
33
+ Requires-Dist: botocore>=1.29.0
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.3.0; extra == "dev"
36
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
37
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
38
+ Requires-Dist: black>=23.0.0; extra == "dev"
39
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
40
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
41
+ Requires-Dist: ruff>=0.7.0; extra == "dev"
42
+ Provides-Extra: docs
43
+ Requires-Dist: sphinx>=6.0.0; extra == "docs"
44
+ Requires-Dist: sphinx-rtd-theme>=1.2.0; extra == "docs"
45
+ Requires-Dist: mkdocs>=1.6.1; extra == "docs"
46
+ Requires-Dist: mkdocs-material>=9.5.44; extra == "docs"
47
+ Provides-Extra: notebooks
48
+ Requires-Dist: jupyter>=1.0.0; extra == "notebooks"
49
+ Requires-Dist: ipykernel>=6.20.0; extra == "notebooks"
50
+ Provides-Extra: sagemaker
51
+ Requires-Dist: boto3>=1.26.0; extra == "sagemaker"
52
+ Requires-Dist: botocore>=1.29.0; extra == "sagemaker"
53
+ Provides-Extra: ocr
54
+ Requires-Dist: Pillow[raqm]>=9.5.0; extra == "ocr"
55
+ Dynamic: license-file
56
+
57
+ # Yomitoku Client
58
+
59
+ <div align="center">
60
+
61
+ [![Language](https://img.shields.io/badge/🌐_English-blue?style=for-the-badge&logo=github)](docs/en/README.md) [![Language](https://img.shields.io/badge/🌐_日本語-red?style=for-the-badge&logo=github)](docs/ja/README.md)
62
+
63
+ **上記のボタンをクリックして、お好みの言語でドキュメントを表示してください**
64
+
65
+ </div>
66
+
67
+ ---
68
+
69
+ ## クイックリンク
70
+
71
+ - 📖 **[English Documentation](docs/en/README.md)** - 英語での完全ガイド
72
+ - 📖 **[日本語ドキュメント](docs/ja/README.md)** - 日本語での完全ガイド
73
+ - 📓 **[Notebook Guide (English)](docs/en/NOTEBOOK_GUIDE.md)** - ステップバイステップのノートブックチュートリアル(英語)
74
+ - 📓 **[ノートブックガイド (日本語)](docs/ja/NOTEBOOK_GUIDE.md)** - ステップバイステップのノートブックチュートリアル
75
+
76
+ Yomitoku Clientは、SageMaker Yomitoku APIの出力を処理し、包括的なフォーマット変換と可視化機能を提供するPythonライブラリです。Yomitoku ProのOCR分析と実用的なデータ処理ワークフローを橋渡しします。
77
+
78
+ ## 主な機能
79
+
80
+ - **SageMaker統合**: Yomitoku Pro OCR結果のシームレスな処理
81
+ - **複数フォーマット対応**: CSV、Markdown、HTML、JSON、PDF形式への変換
82
+ - **検索可能PDF生成**: OCRテキストオーバーレイ付きの検索可能PDFの作成
83
+ - **高度な可視化**: 文書レイアウト分析、要素関係、信頼度スコア
84
+ - **ユーティリティ関数**: 矩形計算、テキスト処理、画像操作
85
+ - **Jupyter Notebook対応**: すぐに使える例とワークフロー
86
+
87
+ ## インストール
88
+
89
+ ### pipを使用
90
+ ```bash
91
+ # GitHubから直接インストール
92
+ pip install git+https://github.com/MLism-Inc/yomitoku-client.git@main
93
+ ```
94
+
95
+ ### uvを使用(推奨)
96
+ ```bash
97
+ # GitHubから直接インストール
98
+ uv add git+https://github.com/MLism-Inc/yomitoku-client.git@main
99
+ ```
100
+
101
+ > **注意**: uvがインストールされていない場合は、以下でインストールできます:
102
+ > ```bash
103
+ > curl -LsSf https://astral.sh/uv/install.sh | sh
104
+ > ```
105
+
106
+ ## クイックスタート
107
+
108
+ ### ステップ1: SageMakerエンドポイントに接続
109
+
110
+ ```python
111
+ import boto3
112
+ import json
113
+ from yomitoku_client.parsers.sagemaker_parser import SageMakerParser
114
+
115
+ # SageMakerランタイムクライアントを初期化
116
+ sagemaker_runtime = boto3.client('sagemaker-runtime')
117
+ ENDPOINT_NAME = 'your-yomitoku-endpoint'
118
+
119
+ # パーサーを初期化
120
+ parser = SageMakerParser()
121
+
122
+ # 文書でSageMakerエンドポイントを呼び出し
123
+ with open('document.pdf', 'rb') as f:
124
+ response = sagemaker_runtime.invoke_endpoint(
125
+ EndpointName=ENDPOINT_NAME,
126
+ ContentType='application/pdf', # または 'image/png', 'image/jpeg'
127
+ Body=f.read(),
128
+ )
129
+
130
+ # レスポンスをパース
131
+ body_bytes = response['Body'].read()
132
+ sagemaker_result = json.loads(body_bytes)
133
+
134
+ # 構造化データに変換
135
+ data = parser.parse_dict(sagemaker_result)
136
+
137
+ print(f"ページ数: {len(data.pages)}")
138
+ print(f"ページ1の段落数: {len(data.pages[0].paragraphs)}")
139
+ print(f"ページ1のテーブル数: {len(data.pages[0].tables)}")
140
+
141
+ # 特定のページにアクセス(page_index: 0=最初のページ)
142
+ page_index = 0 # 最初のページ
143
+ print(f"指定ページの段落数: {len(data.pages[page_index].paragraphs)}")
144
+ ```
145
+
146
+ ### ステップ2: データを異なる形式に変換
147
+
148
+ #### 単一ページ文書(画像)
149
+
150
+ ```python
151
+ # 異なる形式に変換(page_index: 0=最初のページ)
152
+ data.to_csv('output.csv', page_index=0)
153
+ data.to_html('output.html', page_index=0)
154
+ data.to_markdown('output.md', page_index=0)
155
+ data.to_json('output.json', page_index=0)
156
+
157
+ # 画像から検索可能PDFを作成
158
+ data.to_pdf(output_path='searchable.pdf', img='document.png')
159
+ ```
160
+
161
+ #### 複数ページ文書(PDF)
162
+
163
+ ```python
164
+ # 全ページを変換(フォルダ構造を作成)
165
+ data.to_csv_folder('csv_output/')
166
+ data.to_html_folder('html_output/')
167
+ data.to_markdown_folder('markdown_output/')
168
+ data.to_json_folder('json_output/')
169
+
170
+ # 検索可能PDFを作成(既存のPDFに検索可能テキストを追加)
171
+ data.to_pdf(output_path='enhanced.pdf', pdf='original.pdf')
172
+
173
+ # または個別のページを変換(page_index: 0=最初のページ、1=2番目のページ)
174
+ data.to_csv('page1.csv', page_index=0) # 最初のページ
175
+ data.to_html('page2.html', page_index=1) # 2番目のページ
176
+ ```
177
+
178
+ #### テーブルデータ抽出
179
+
180
+ ```python
181
+ # 様々な形式でテーブルをエクスポート(page_index: 0=最初のページ)
182
+ data.export_tables(
183
+ output_folder='tables/',
184
+ output_format='csv', # または 'html', 'json', 'text'
185
+ page_index=0
186
+ )
187
+
188
+ # 複数ページ文書の場合
189
+ data.export_tables(
190
+ output_folder='all_tables/',
191
+ output_format='csv'
192
+ )
193
+
194
+ # 特定のページのテーブルのみをエクスポート
195
+ data.export_tables(
196
+ output_folder='page1_tables/',
197
+ output_format='csv',
198
+ page_index=0 # 最初のページ
199
+ )
200
+ ```
201
+
202
+ ### ステップ3: 結果を可視化
203
+
204
+ #### 単一画像の可視化
205
+
206
+ ```python
207
+ # OCRテキストの可視化
208
+ result_img = data.pages[0].visualize(
209
+ image_path='document.png',
210
+ viz_type='ocr',
211
+ output_path='ocr_visualization.png'
212
+ )
213
+
214
+ # レイアウト詳細の可視化(テキスト、テーブル、図)
215
+ result_img = data.pages[0].visualize(
216
+ image_path='document.png',
217
+ viz_type='layout_detail',
218
+ output_path='layout_visualization.png'
219
+ )
220
+ ```
221
+
222
+ #### 複数画像の一括可視化
223
+
224
+ ```python
225
+ # 全ページのOCR結果を一括可視化(0.png, 1.png, 2.png...として保存)
226
+ data.export_viz_images(
227
+ image_path='document.pdf',
228
+ folder_path='ocr_results/',
229
+ viz_type='ocr'
230
+ )
231
+
232
+ # 全ページのレイアウト詳細を一括可視化
233
+ data.export_viz_images(
234
+ image_path='document.pdf',
235
+ folder_path='layout_results/',
236
+ viz_type='layout_detail'
237
+ )
238
+
239
+ # 特定のページのみ可視化
240
+ data.export_viz_images(
241
+ image_path='document.pdf',
242
+ folder_path='page1_results/',
243
+ viz_type='layout_detail',
244
+ page_index=0 # 最初のページのみ
245
+ )
246
+ ```
247
+
248
+ #### PDF可視化
249
+
250
+ ```python
251
+ # PDFの特定ページを可視化
252
+ result_img = data.pages[0].visualize(
253
+ image_path='document.pdf',
254
+ viz_type='layout_detail',
255
+ output_path='pdf_visualization.png',
256
+ page_index=0 # 可視化するページを指定
257
+ )
258
+ ```
259
+
260
+ ## サポート形式
261
+
262
+ - **CSV**: 適切なセル処理による表形式データのエクスポート
263
+ - **Markdown**: テーブルと見出しを含む構造化文書形式
264
+ - **HTML**: 適切なスタイリングを含むWeb対応形式
265
+ - **JSON**: 完全な文書構造を含む構造化データエクスポート
266
+ - **PDF**: OCRテキストオーバーレイ付きの検索可能PDF生成
267
+
268
+ ## ライセンス
269
+
270
+ Apache License 2.0 - 詳細はLICENSEファイルを参照してください。
271
+
272
+ ## お問い合わせ
273
+
274
+ ご質問やサポートについては: support-aws-marketplace@mlism.com
@@ -0,0 +1,218 @@
1
+ # Yomitoku Client
2
+
3
+ <div align="center">
4
+
5
+ [![Language](https://img.shields.io/badge/🌐_English-blue?style=for-the-badge&logo=github)](docs/en/README.md) [![Language](https://img.shields.io/badge/🌐_日本語-red?style=for-the-badge&logo=github)](docs/ja/README.md)
6
+
7
+ **上記のボタンをクリックして、お好みの言語でドキュメントを表示してください**
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ ## クイックリンク
14
+
15
+ - 📖 **[English Documentation](docs/en/README.md)** - 英語での完全ガイド
16
+ - 📖 **[日本語ドキュメント](docs/ja/README.md)** - 日本語での完全ガイド
17
+ - 📓 **[Notebook Guide (English)](docs/en/NOTEBOOK_GUIDE.md)** - ステップバイステップのノートブックチュートリアル(英語)
18
+ - 📓 **[ノートブックガイド (日本語)](docs/ja/NOTEBOOK_GUIDE.md)** - ステップバイステップのノートブックチュートリアル
19
+
20
+ Yomitoku Clientは、SageMaker Yomitoku APIの出力を処理し、包括的なフォーマット変換と可視化機能を提供するPythonライブラリです。Yomitoku ProのOCR分析と実用的なデータ処理ワークフローを橋渡しします。
21
+
22
+ ## 主な機能
23
+
24
+ - **SageMaker統合**: Yomitoku Pro OCR結果のシームレスな処理
25
+ - **複数フォーマット対応**: CSV、Markdown、HTML、JSON、PDF形式への変換
26
+ - **検索可能PDF生成**: OCRテキストオーバーレイ付きの検索可能PDFの作成
27
+ - **高度な可視化**: 文書レイアウト分析、要素関係、信頼度スコア
28
+ - **ユーティリティ関数**: 矩形計算、テキスト処理、画像操作
29
+ - **Jupyter Notebook対応**: すぐに使える例とワークフロー
30
+
31
+ ## インストール
32
+
33
+ ### pipを使用
34
+ ```bash
35
+ # GitHubから直接インストール
36
+ pip install git+https://github.com/MLism-Inc/yomitoku-client.git@main
37
+ ```
38
+
39
+ ### uvを使用(推奨)
40
+ ```bash
41
+ # GitHubから直接インストール
42
+ uv add git+https://github.com/MLism-Inc/yomitoku-client.git@main
43
+ ```
44
+
45
+ > **注意**: uvがインストールされていない場合は、以下でインストールできます:
46
+ > ```bash
47
+ > curl -LsSf https://astral.sh/uv/install.sh | sh
48
+ > ```
49
+
50
+ ## クイックスタート
51
+
52
+ ### ステップ1: SageMakerエンドポイントに接続
53
+
54
+ ```python
55
+ import boto3
56
+ import json
57
+ from yomitoku_client.parsers.sagemaker_parser import SageMakerParser
58
+
59
+ # SageMakerランタイムクライアントを初期化
60
+ sagemaker_runtime = boto3.client('sagemaker-runtime')
61
+ ENDPOINT_NAME = 'your-yomitoku-endpoint'
62
+
63
+ # パーサーを初期化
64
+ parser = SageMakerParser()
65
+
66
+ # 文書でSageMakerエンドポイントを呼び出し
67
+ with open('document.pdf', 'rb') as f:
68
+ response = sagemaker_runtime.invoke_endpoint(
69
+ EndpointName=ENDPOINT_NAME,
70
+ ContentType='application/pdf', # または 'image/png', 'image/jpeg'
71
+ Body=f.read(),
72
+ )
73
+
74
+ # レスポンスをパース
75
+ body_bytes = response['Body'].read()
76
+ sagemaker_result = json.loads(body_bytes)
77
+
78
+ # 構造化データに変換
79
+ data = parser.parse_dict(sagemaker_result)
80
+
81
+ print(f"ページ数: {len(data.pages)}")
82
+ print(f"ページ1の段落数: {len(data.pages[0].paragraphs)}")
83
+ print(f"ページ1のテーブル数: {len(data.pages[0].tables)}")
84
+
85
+ # 特定のページにアクセス(page_index: 0=最初のページ)
86
+ page_index = 0 # 最初のページ
87
+ print(f"指定ページの段落数: {len(data.pages[page_index].paragraphs)}")
88
+ ```
89
+
90
+ ### ステップ2: データを異なる形式に変換
91
+
92
+ #### 単一ページ文書(画像)
93
+
94
+ ```python
95
+ # 異なる形式に変換(page_index: 0=最初のページ)
96
+ data.to_csv('output.csv', page_index=0)
97
+ data.to_html('output.html', page_index=0)
98
+ data.to_markdown('output.md', page_index=0)
99
+ data.to_json('output.json', page_index=0)
100
+
101
+ # 画像から検索可能PDFを作成
102
+ data.to_pdf(output_path='searchable.pdf', img='document.png')
103
+ ```
104
+
105
+ #### 複数ページ文書(PDF)
106
+
107
+ ```python
108
+ # 全ページを変換(フォルダ構造を作成)
109
+ data.to_csv_folder('csv_output/')
110
+ data.to_html_folder('html_output/')
111
+ data.to_markdown_folder('markdown_output/')
112
+ data.to_json_folder('json_output/')
113
+
114
+ # 検索可能PDFを作成(既存のPDFに検索可能テキストを追加)
115
+ data.to_pdf(output_path='enhanced.pdf', pdf='original.pdf')
116
+
117
+ # または個別のページを変換(page_index: 0=最初のページ、1=2番目のページ)
118
+ data.to_csv('page1.csv', page_index=0) # 最初のページ
119
+ data.to_html('page2.html', page_index=1) # 2番目のページ
120
+ ```
121
+
122
+ #### テーブルデータ抽出
123
+
124
+ ```python
125
+ # 様々な形式でテーブルをエクスポート(page_index: 0=最初のページ)
126
+ data.export_tables(
127
+ output_folder='tables/',
128
+ output_format='csv', # または 'html', 'json', 'text'
129
+ page_index=0
130
+ )
131
+
132
+ # 複数ページ文書の場合
133
+ data.export_tables(
134
+ output_folder='all_tables/',
135
+ output_format='csv'
136
+ )
137
+
138
+ # 特定のページのテーブルのみをエクスポート
139
+ data.export_tables(
140
+ output_folder='page1_tables/',
141
+ output_format='csv',
142
+ page_index=0 # 最初のページ
143
+ )
144
+ ```
145
+
146
+ ### ステップ3: 結果を可視化
147
+
148
+ #### 単一画像の可視化
149
+
150
+ ```python
151
+ # OCRテキストの可視化
152
+ result_img = data.pages[0].visualize(
153
+ image_path='document.png',
154
+ viz_type='ocr',
155
+ output_path='ocr_visualization.png'
156
+ )
157
+
158
+ # レイアウト詳細の可視化(テキスト、テーブル、図)
159
+ result_img = data.pages[0].visualize(
160
+ image_path='document.png',
161
+ viz_type='layout_detail',
162
+ output_path='layout_visualization.png'
163
+ )
164
+ ```
165
+
166
+ #### 複数画像の一括可視化
167
+
168
+ ```python
169
+ # 全ページのOCR結果を一括可視化(0.png, 1.png, 2.png...として保存)
170
+ data.export_viz_images(
171
+ image_path='document.pdf',
172
+ folder_path='ocr_results/',
173
+ viz_type='ocr'
174
+ )
175
+
176
+ # 全ページのレイアウト詳細を一括可視化
177
+ data.export_viz_images(
178
+ image_path='document.pdf',
179
+ folder_path='layout_results/',
180
+ viz_type='layout_detail'
181
+ )
182
+
183
+ # 特定のページのみ可視化
184
+ data.export_viz_images(
185
+ image_path='document.pdf',
186
+ folder_path='page1_results/',
187
+ viz_type='layout_detail',
188
+ page_index=0 # 最初のページのみ
189
+ )
190
+ ```
191
+
192
+ #### PDF可視化
193
+
194
+ ```python
195
+ # PDFの特定ページを可視化
196
+ result_img = data.pages[0].visualize(
197
+ image_path='document.pdf',
198
+ viz_type='layout_detail',
199
+ output_path='pdf_visualization.png',
200
+ page_index=0 # 可視化するページを指定
201
+ )
202
+ ```
203
+
204
+ ## サポート形式
205
+
206
+ - **CSV**: 適切なセル処理による表形式データのエクスポート
207
+ - **Markdown**: テーブルと見出しを含む構造化文書形式
208
+ - **HTML**: 適切なスタイリングを含むWeb対応形式
209
+ - **JSON**: 完全な文書構造を含む構造化データエクスポート
210
+ - **PDF**: OCRテキストオーバーレイ付きの検索可能PDF生成
211
+
212
+ ## ライセンス
213
+
214
+ Apache License 2.0 - 詳細はLICENSEファイルを参照してください。
215
+
216
+ ## お問い合わせ
217
+
218
+ ご質問やサポートについては: support-aws-marketplace@mlism.com