deepdoc-lib 0.2.0__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 (88) hide show
  1. deepdoc_lib-0.2.0/.env.example +57 -0
  2. deepdoc_lib-0.2.0/.github/workflows/ci.yml +31 -0
  3. deepdoc_lib-0.2.0/.github/workflows/publish.yml +86 -0
  4. deepdoc_lib-0.2.0/LICENSE +201 -0
  5. deepdoc_lib-0.2.0/MANIFEST.in +34 -0
  6. deepdoc_lib-0.2.0/PKG-INFO +246 -0
  7. deepdoc_lib-0.2.0/README.md +192 -0
  8. deepdoc_lib-0.2.0/deepdoc/README.md +122 -0
  9. deepdoc_lib-0.2.0/deepdoc/README_zh.md +116 -0
  10. deepdoc_lib-0.2.0/deepdoc/__init__.py +43 -0
  11. deepdoc_lib-0.2.0/deepdoc/_version.py +34 -0
  12. deepdoc_lib-0.2.0/deepdoc/common/__init__.py +52 -0
  13. deepdoc_lib-0.2.0/deepdoc/common/config_utils.py +63 -0
  14. deepdoc_lib-0.2.0/deepdoc/common/connection_utils.py +73 -0
  15. deepdoc_lib-0.2.0/deepdoc/common/file_utils.py +19 -0
  16. deepdoc_lib-0.2.0/deepdoc/common/misc_utils.py +44 -0
  17. deepdoc_lib-0.2.0/deepdoc/common/model_store.py +369 -0
  18. deepdoc_lib-0.2.0/deepdoc/common/settings.py +42 -0
  19. deepdoc_lib-0.2.0/deepdoc/common/tiktoken_cache.py +84 -0
  20. deepdoc_lib-0.2.0/deepdoc/common/token_utils.py +96 -0
  21. deepdoc_lib-0.2.0/deepdoc/config.py +149 -0
  22. deepdoc_lib-0.2.0/deepdoc/depend/find_codec.py +42 -0
  23. deepdoc_lib-0.2.0/deepdoc/depend/nltk_manager.py +114 -0
  24. deepdoc_lib-0.2.0/deepdoc/depend/prompts/vision_llm_describe_prompt.md +23 -0
  25. deepdoc_lib-0.2.0/deepdoc/depend/prompts/vision_llm_figure_describe_prompt.md +24 -0
  26. deepdoc_lib-0.2.0/deepdoc/depend/prompts.py +35 -0
  27. deepdoc_lib-0.2.0/deepdoc/depend/rag_tokenizer.py +578 -0
  28. deepdoc_lib-0.2.0/deepdoc/depend/simple_cv_model.py +469 -0
  29. deepdoc_lib-0.2.0/deepdoc/depend/surname.py +91 -0
  30. deepdoc_lib-0.2.0/deepdoc/depend/timeout.py +73 -0
  31. deepdoc_lib-0.2.0/deepdoc/depend/vision_llm_chunk.py +35 -0
  32. deepdoc_lib-0.2.0/deepdoc/dict/README.md +19 -0
  33. deepdoc_lib-0.2.0/deepdoc/dict/huqie.txt +555629 -0
  34. deepdoc_lib-0.2.0/deepdoc/download_models.py +169 -0
  35. deepdoc_lib-0.2.0/deepdoc/llm_adapter/__init__.py +15 -0
  36. deepdoc_lib-0.2.0/deepdoc/llm_adapter/adapter.py +223 -0
  37. deepdoc_lib-0.2.0/deepdoc/llm_adapter/utils.py +104 -0
  38. deepdoc_lib-0.2.0/deepdoc/llm_adapter/vision.py +163 -0
  39. deepdoc_lib-0.2.0/deepdoc/parser/__init__.py +42 -0
  40. deepdoc_lib-0.2.0/deepdoc/parser/docling_parser.py +889 -0
  41. deepdoc_lib-0.2.0/deepdoc/parser/docx_parser.py +150 -0
  42. deepdoc_lib-0.2.0/deepdoc/parser/excel_parser.py +270 -0
  43. deepdoc_lib-0.2.0/deepdoc/parser/figure_parser.py +182 -0
  44. deepdoc_lib-0.2.0/deepdoc/parser/html_parser.py +221 -0
  45. deepdoc_lib-0.2.0/deepdoc/parser/json_parser.py +179 -0
  46. deepdoc_lib-0.2.0/deepdoc/parser/markdown_parser.py +321 -0
  47. deepdoc_lib-0.2.0/deepdoc/parser/mineru_parser.py +646 -0
  48. deepdoc_lib-0.2.0/deepdoc/parser/pdf_parser.py +1591 -0
  49. deepdoc_lib-0.2.0/deepdoc/parser/ppt_parser.py +96 -0
  50. deepdoc_lib-0.2.0/deepdoc/parser/resume/__init__.py +109 -0
  51. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/__init__.py +15 -0
  52. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/corporations.py +128 -0
  53. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/degrees.py +44 -0
  54. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/industries.py +712 -0
  55. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/regions.py +789 -0
  56. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/res/corp.tks.freq.json +65 -0
  57. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/res/corp_baike_len.csv +31480 -0
  58. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/res/corp_tag.json +14939 -0
  59. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/res/good_corp.json +911 -0
  60. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/res/good_sch.json +595 -0
  61. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/res/school.rank.csv +1627 -0
  62. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/res/schools.csv +5713 -0
  63. deepdoc_lib-0.2.0/deepdoc/parser/resume/entities/schools.py +91 -0
  64. deepdoc_lib-0.2.0/deepdoc/parser/resume/step_one.py +189 -0
  65. deepdoc_lib-0.2.0/deepdoc/parser/resume/step_two.py +692 -0
  66. deepdoc_lib-0.2.0/deepdoc/parser/tcadp_parser.py +538 -0
  67. deepdoc_lib-0.2.0/deepdoc/parser/txt_parser.py +64 -0
  68. deepdoc_lib-0.2.0/deepdoc/parser/utils.py +33 -0
  69. deepdoc_lib-0.2.0/deepdoc/vision/__init__.py +90 -0
  70. deepdoc_lib-0.2.0/deepdoc/vision/layout_recognizer.py +481 -0
  71. deepdoc_lib-0.2.0/deepdoc/vision/ocr.py +757 -0
  72. deepdoc_lib-0.2.0/deepdoc/vision/operators.py +733 -0
  73. deepdoc_lib-0.2.0/deepdoc/vision/postprocess.py +370 -0
  74. deepdoc_lib-0.2.0/deepdoc/vision/recognizer.py +451 -0
  75. deepdoc_lib-0.2.0/deepdoc/vision/seeit.py +87 -0
  76. deepdoc_lib-0.2.0/deepdoc/vision/t_ocr.py +101 -0
  77. deepdoc_lib-0.2.0/deepdoc/vision/t_recognizer.py +186 -0
  78. deepdoc_lib-0.2.0/deepdoc/vision/table_structure_recognizer.py +617 -0
  79. deepdoc_lib-0.2.0/deepdoc_config.example.yaml +16 -0
  80. deepdoc_lib-0.2.0/deepdoc_lib.egg-info/PKG-INFO +246 -0
  81. deepdoc_lib-0.2.0/deepdoc_lib.egg-info/SOURCES.txt +86 -0
  82. deepdoc_lib-0.2.0/deepdoc_lib.egg-info/dependency_links.txt +1 -0
  83. deepdoc_lib-0.2.0/deepdoc_lib.egg-info/entry_points.txt +2 -0
  84. deepdoc_lib-0.2.0/deepdoc_lib.egg-info/requires.txt +47 -0
  85. deepdoc_lib-0.2.0/deepdoc_lib.egg-info/top_level.txt +4 -0
  86. deepdoc_lib-0.2.0/pyproject.toml +105 -0
  87. deepdoc_lib-0.2.0/scripts/download_models.py +10 -0
  88. deepdoc_lib-0.2.0/setup.cfg +4 -0
@@ -0,0 +1,57 @@
1
+ # DeepDoc 视觉模型配置示例
2
+ # 复制此文件为 .env 并填写实际的配置信息
3
+
4
+ # ===========================================
5
+ # 视觉模型 API 配置
6
+ # ===========================================
7
+
8
+ # API 密钥 - 从对应服务商获取
9
+ # OpenAI: https://platform.openai.com/account/api-keys
10
+ # 阿里云 DashScope: https://dashscope.aliyuncs.com/
11
+ # 智谱AI: https://open.bigmodel.cn/
12
+ # Gemini: https://makersuite.google.com/app/apikey
13
+ DEEPDOC_VISION_API_KEY=your_api_key_here
14
+
15
+ # 模型名称 - 根据选择的提供商设置对应模型
16
+ # OpenAI: gpt-4-vision-preview, gpt-4o, gpt-4o-mini
17
+ # 阿里云: qwen-vl-max, qwen-vl-plus, qwen2-vl-72b-instruct
18
+ # 智谱AI: glm-4v, glm-4v-plus
19
+ # Gemini: gemini-pro-vision, gemini-1.5-pro
20
+ DEEPDOC_VISION_MODEL=qwen-vl-max
21
+
22
+ # API 基础 URL - 可选,大部分服务商使用默认值
23
+ # OpenAI: https://api.openai.com/v1 (默认)
24
+ # 阿里云: https://dashscope.aliyuncs.com/api/v1 (默认) 或 https://dashscope.aliyuncs.com/compatible-mode/v1
25
+ # 智谱AI: https://open.bigmodel.cn/api/paas/v4 (默认)
26
+ DEEPDOC_VISION_BASE_URL=
27
+
28
+ # 提供商选择 - 支持以下选项:
29
+ # openai - OpenAI GPT-4 Vision
30
+ # qwen - 阿里云通义千问
31
+ # zhipu - 智谱AI
32
+ # gemini - Google Gemini
33
+ # ollama - 本地 Ollama 服务
34
+ # anthropic - Anthropic Claude (需额外配置)
35
+ DEEPDOC_VISION_PROVIDER=qwen
36
+
37
+ # ===========================================
38
+ # 可选配置
39
+ # ===========================================
40
+
41
+ # 语言设置 - 影响模型回复语言
42
+ # Chinese, English 等
43
+ DEEPDOC_VISION_LANG=Chinese
44
+
45
+ # ===========================================
46
+ # 配置说明
47
+ # ===========================================
48
+ #
49
+ # 1. 复制此文件为 .env: cp .env.example .env
50
+ # 2. 根据你的需求修改相应的配置值
51
+ # 3. 确保 API 密钥有效且有足够的使用额度
52
+ # 4. 对于生产环境,建议使用环境变量或密钥管理服务
53
+ #
54
+ # 支持的提供商和模型列表请参考:
55
+ # https://github.com/ragflow/deepdoc/blob/main/README.md
56
+ #
57
+ # ===========================================
@@ -0,0 +1,31 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ pytest:
10
+ name: Pytest (${{ matrix.python-version }})
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ cache: "pip"
24
+
25
+ - name: Install dependencies
26
+ run: |
27
+ python -m pip install --upgrade pip
28
+ python -m pip install -e . pytest
29
+
30
+ - name: Run tests
31
+ run: python -m pytest tests
@@ -0,0 +1,86 @@
1
+ # This workflow handles the distribution of Python packages.
2
+ # 1. Automatic: Every push/tag builds the distribution.
3
+ # 2. Automatic: Tag pushes (refs/tags/*) deploy to TestPyPI.
4
+ # 3. Manual: Production releases to PyPI require a manual trigger (workflow_dispatch)
5
+ # to prevent accidental deployments.
6
+
7
+ name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
8
+
9
+ on:
10
+ push:
11
+ workflow_dispatch:
12
+
13
+ jobs:
14
+ build:
15
+ name: Build distribution 📦
16
+ runs-on: ubuntu-latest
17
+
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ with:
21
+ persist-credentials: false
22
+ - name: Set up Python
23
+ uses: actions/setup-python@v5
24
+ with:
25
+ python-version: "3.x"
26
+ - name: Install pypa/build
27
+ run: >-
28
+ python3 -m
29
+ pip install
30
+ build
31
+ --user
32
+ - name: Build a binary wheel and a source tarball
33
+ run: python3 -m build
34
+ - name: Store the distribution packages
35
+ uses: actions/upload-artifact@v4
36
+ with:
37
+ name: python-package-distributions
38
+ path: dist/
39
+
40
+ publish-to-pypi:
41
+ name: >-
42
+ Publish Python 🐍 distribution 📦 to PyPI
43
+ # Manual dispatch required to prevent accidental production releases
44
+ if: github.event_name == 'workflow_dispatch'
45
+ needs:
46
+ - build
47
+ runs-on: ubuntu-latest
48
+ environment:
49
+ name: pypi
50
+ url: https://pypi.org/p/deepdoc-lib
51
+ permissions:
52
+ id-token: write # IMPORTANT: mandatory for trusted publishing
53
+
54
+ steps:
55
+ - name: Download all the dists
56
+ uses: actions/download-artifact@v4
57
+ with:
58
+ name: python-package-distributions
59
+ path: dist/
60
+ - name: Publish distribution 📦 to PyPI
61
+ uses: pypa/gh-action-pypi-publish@release/v1
62
+
63
+ publish-to-testpypi:
64
+ name: Publish Python 🐍 distribution 📦 to TestPyPI
65
+ if: startsWith(github.ref, 'refs/tags/') # only publish to TestPyPI on tag pushes
66
+ needs:
67
+ - build
68
+ runs-on: ubuntu-latest
69
+
70
+ environment:
71
+ name: testpypi
72
+ url: https://test.pypi.org/p/deepdoc-lib
73
+
74
+ permissions:
75
+ id-token: write # IMPORTANT: mandatory for trusted publishing
76
+
77
+ steps:
78
+ - name: Download all the dists
79
+ uses: actions/download-artifact@v4
80
+ with:
81
+ name: python-package-distributions
82
+ path: dist/
83
+ - name: Publish distribution 📦 to TestPyPI
84
+ uses: pypa/gh-action-pypi-publish@release/v1
85
+ with:
86
+ repository-url: https://test.pypi.org/legacy/
@@ -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,34 @@
1
+ # Include main project files
2
+ include README.md
3
+ include LICENSE
4
+ include *.yaml
5
+
6
+ # Include all deepdoc package data
7
+ recursive-include deepdoc *.py
8
+ recursive-include deepdoc *.md
9
+ recursive-include deepdoc *.txt
10
+ recursive-include deepdoc *.json
11
+ recursive-include deepdoc *.yaml
12
+ recursive-include deepdoc *.yml
13
+ recursive-include deepdoc *.csv
14
+
15
+ # Exclude heavyweight model artifacts (resolved at runtime)
16
+ prune deepdoc/rag/res
17
+
18
+ # Exclude unwanted files
19
+ global-exclude *.pyc
20
+ global-exclude __pycache__
21
+ global-exclude .git*
22
+ global-exclude *.egg-info
23
+ prune deepdoc/__pycache__
24
+ prune deepdoc/*/__pycache__
25
+ prune deepdoc/*/*/__pycache__
26
+ prune deepdoc/*/*/*/__pycache__
27
+
28
+ # Exclude test files from package
29
+ prune tests
30
+ global-exclude test_*
31
+
32
+ # Exclude build artifacts
33
+ prune dist
34
+ prune build
@@ -0,0 +1,246 @@
1
+ Metadata-Version: 2.4
2
+ Name: deepdoc_lib
3
+ Version: 0.2.0
4
+ Summary: [RAGFlow](https://ragflow.io/) is an open-source RAG (Retrieval-Augmented Generation) engine based on deep document understanding. It offers a streamlined RAG workflow for businesses of any scale, combining LLM (Large Language Models) to provide truthful question-answering capabilities, backed by well-founded citations from various complex formatted data.
5
+ Author-email: Zhichang Yu <yuzhichang@gmail.com>
6
+ Requires-Python: <3.14,>=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: datrie>=0.8.2
10
+ Requires-Dist: anthropic>=0.69.0
11
+ Requires-Dist: beartype<0.19.0,>=0.18.5
12
+ Requires-Dist: beautifulsoup4>=4.12.0
13
+ Requires-Dist: chardet>=5.2.0
14
+ Requires-Dist: demjson3>=3.0.6
15
+ Requires-Dist: hanziconv>=0.3.2
16
+ Requires-Dist: html5lib>=1.1
17
+ Requires-Dist: jinja2>=3.1.0
18
+ Requires-Dist: modelscope<2.0.0,>=1.20.0
19
+ Requires-Dist: markdown>=3.6
20
+ Requires-Dist: nltk>=3.9.1
21
+ Requires-Dist: numpy<2.0.0,>=1.26.0
22
+ Requires-Dist: ollama>=0.6.1
23
+ Requires-Dist: onnxruntime>=1.19.2
24
+ Requires-Dist: openai>=1.45.0
25
+ Requires-Dist: opencv-python>=4.10.0.84
26
+ Requires-Dist: opencv-python-headless>=4.10.0.84
27
+ Requires-Dist: openpyxl<4.0.0,>=3.1.0
28
+ Requires-Dist: pandas<3.0.0,>=2.2.0
29
+ Requires-Dist: pdfplumber>=0.10.4
30
+ Requires-Dist: pillow>=11.0.0
31
+ Requires-Dist: pyclipper>=1.3.0.post5
32
+ Requires-Dist: pypdf>=6.0.0
33
+ Requires-Dist: python-pptx<2.0.0,>=1.0.2
34
+ Requires-Dist: python-docx<2.0.0,>=1.1.2
35
+ Requires-Dist: pyyaml>=6.0.0
36
+ Requires-Dist: requests>=2.32.2
37
+ Requires-Dist: scikit-learn>=1.5.0
38
+ Requires-Dist: shapely>=2.0.5
39
+ Requires-Dist: six>=1.16.0
40
+ Requires-Dist: strenum>=0.4.15
41
+ Requires-Dist: tencentcloud-sdk-python>=3.0.1215
42
+ Requires-Dist: tiktoken>=0.7.0
43
+ Requires-Dist: xgboost<2.0.0,>=1.6.0
44
+ Requires-Dist: xpinyin>=0.7.6
45
+ Requires-Dist: zhipuai>=2.0.1
46
+ Requires-Dist: google-generativeai<0.9.0,>=0.8.1
47
+ Requires-Dist: trio>=0.29.0
48
+ Requires-Dist: setuptools<76.0.0,>=75.2.0
49
+ Requires-Dist: huggingface-hub<0.26.0,>=0.25.0
50
+ Provides-Extra: gpu
51
+ Requires-Dist: onnxruntime-gpu>=1.19.2; (sys_platform != "darwin" and platform_machine == "x86_64") and extra == "gpu"
52
+ Requires-Dist: torch; extra == "gpu"
53
+ Dynamic: license-file
54
+
55
+ # Deepdoc
56
+
57
+ ### Installations
58
+
59
+ CPU-only (default):
60
+
61
+ ```bash
62
+ pip install deepdoc-lib
63
+ ```
64
+
65
+ GPU (Linux x86_64 only):
66
+
67
+ ```bash
68
+ pip install deepdoc-lib[gpu]
69
+ ```
70
+
71
+ Note: `onnxruntime` (CPU) and `onnxruntime-gpu` should not be installed together. If you're switching an existing environment to GPU, uninstall CPU ORT first:
72
+
73
+ ```bash
74
+ pip uninstall -y onnxruntime
75
+ pip install onnxruntime-gpu==1.19.2
76
+ ```
77
+
78
+ ### Parser Usage
79
+
80
+ ```python
81
+ from deepdoc import (
82
+ DocxParser,
83
+ ExcelParser,
84
+ HtmlParser,
85
+ PdfModelConfig,
86
+ PdfParser,
87
+ TokenizerConfig,
88
+ )
89
+
90
+ # Build configs
91
+ # Method 1: Explicit configuration (offline mode)
92
+ tokenizer_cfg = TokenizerConfig(
93
+ offline=True,
94
+ nltk_data_dir="/path/to/nltk_data",
95
+ )
96
+ pdf_model_cfg = PdfModelConfig(
97
+ vision_model_dir="/path/to/models/vision",
98
+ xgb_model_dir="/path/to/models/xgb",
99
+ model_provider="local",
100
+ )
101
+
102
+ # Method 2: Empty configuration (auto-download models and nltk_data)
103
+ # tokenizer_cfg = TokenizerConfig()
104
+ # pdf_model_cfg = PdfModelConfig()
105
+
106
+
107
+ # Parse PDF
108
+ pdf_parser = PdfParser(model_cfg=pdf_model_cfg, tokenizer_cfg=tokenizer_cfg)
109
+ result = pdf_parser("document.pdf")
110
+
111
+ # Parse DOCX / HTML (tokenizer only)
112
+ docx_parser = DocxParser(tokenizer_cfg=tokenizer_cfg)
113
+ html_parser = HtmlParser(tokenizer_cfg=tokenizer_cfg)
114
+
115
+ # Parse Excel (no model/tokenizer dependency)
116
+ excel_parser = ExcelParser()
117
+ with open("data.xlsx", "rb") as f:
118
+ result = excel_parser(f.read())
119
+ ```
120
+
121
+ Or use explicit env factories:
122
+
123
+ ```python
124
+ tokenizer_cfg = TokenizerConfig.from_env()
125
+ pdf_model_cfg = PdfModelConfig.from_env()
126
+ pdf_parser = PdfParser(model_cfg=pdf_model_cfg, tokenizer_cfg=tokenizer_cfg)
127
+ ```
128
+
129
+ Or rely on defaults (env + cache). Deepdoc will look for cached bundles under
130
+ `$DEEPDOC_MODEL_HOME` (or `~/.cache/deepdoc`) and only download missing files
131
+ when the provider allows remote access:
132
+
133
+ ```python
134
+ pdf_parser = PdfParser()
135
+ ```
136
+
137
+ env definitions:
138
+
139
+ ```bash
140
+ # provider: auto | local | modelscope
141
+ export DEEPDOC_MODEL_PROVIDER=auto
142
+
143
+ # shared model cache root (default: ~/.cache/deepdoc)
144
+ export DEEPDOC_MODEL_HOME=/path/to/deepdoc-models
145
+
146
+ # optional bundle-specific local directories
147
+ export DEEPDOC_VISION_MODEL_DIR=/path/to/vision
148
+ export DEEPDOC_XGB_MODEL_DIR=/path/to/xgb
149
+
150
+ # single combined ModelScope repo (all bundles in one repo)
151
+ # (default: Xorbits/deepdoc)
152
+ export DEEPDOC_MODELSCOPE_REPO=Xorbits/deepdoc
153
+ # optional shared revision (default: master)
154
+ export DEEPDOC_MODELSCOPE_REVISION=master
155
+
156
+ # offline mode for tokenizer NLTK auto-download
157
+ export DEEPDOC_OFFLINE=0
158
+
159
+ # optional NLTK data controls for tokenizer
160
+ export DEEPDOC_NLTK_DATA_DIR=/path/to/nltk_data
161
+ ```
162
+
163
+ ### Download model artifacts
164
+
165
+ To pre-download all model bundles (vision/xgb/tokenizer) into the default cache directory (`~/.cache/deepdoc`), run:
166
+
167
+ ```bash
168
+ deepdoc-download-models
169
+ # or (from source checkout)
170
+ python -m deepdoc.download_models
171
+ ```
172
+
173
+ If you want to override the cache location, set `DEEPDOC_MODEL_HOME`:
174
+
175
+ ```bash
176
+ export DEEPDOC_MODEL_HOME=./models
177
+ deepdoc-download-models
178
+ ```
179
+
180
+ By default this also downloads the required NLTK resources into `~/.cache/deepdoc/nltk_data` (or `$DEEPDOC_MODEL_HOME/nltk_data`) and the cached `cl100k_base` tiktoken file into `~/.cache/deepdoc/tiktoken_cache` (or `$DEEPDOC_MODEL_HOME/tiktoken_cache`). `deepdoc.common.token_utils` automatically points `TIKTOKEN_CACHE_DIR` at the same location unless you override it with `DEEPDOC_TIKTOKEN_CACHE_DIR` or `TIKTOKEN_CACHE_DIR`.
181
+
182
+ If you want to skip either optional offline asset, use:
183
+
184
+ ```bash
185
+ deepdoc-download-models --no-nltk --no-tiktoken
186
+ ```
187
+
188
+
189
+ ### Vision Model Usage
190
+
191
+ ``` python
192
+ from deepdoc import create_vision_model
193
+ ```
194
+
195
+ - Use Environment Variable
196
+
197
+ ```bash
198
+ # Vision model configs
199
+ export DEEPDOC_VISION_PROVIDER="qwen"
200
+ export DEEPDOC_VISION_API_KEY="your-api-key"
201
+ export DEEPDOC_VISION_MODEL="qwen-vl-max"
202
+ export DEEPDOC_VISION_LANG="Chinese"
203
+ export DEEPDOC_VISION_BASE_URL="http://your_base_url"
204
+
205
+ # Other configs
206
+ export DEEPDOC_LIGHTEN=0 # Whether to use lighten mode
207
+ ```
208
+
209
+ ``` python
210
+ vision_model = create_vision_model()
211
+ ```
212
+
213
+ - Use Default Provider
214
+
215
+ ``` bash
216
+ export DEEPDOC_VISION_API_KEY="your-api-key"
217
+ ```
218
+
219
+ ``` python
220
+ vision_model = create_vision_model("qwen")
221
+ ```
222
+
223
+ Supported providers: ["openai", "qwen", "zhipu", "ollama", "gemini", "anthropic"]
224
+
225
+ - Use Configuration File
226
+
227
+ Create `deepdoc_config.yaml`:
228
+
229
+ ```yaml
230
+ vision_model:
231
+ provider: "qwen"
232
+ model_name: "qwen-vl-max"
233
+ api_key: "your-api-key"
234
+ lang: "Chinese"
235
+ base_url : "http://your-base-url"
236
+ ```
237
+
238
+ ``` python
239
+ vision_model = create_vision_model("/path/to/deepdoc_config.yaml")
240
+ ```
241
+
242
+ #### Run
243
+ ``` python
244
+ with open("image.jpg", "rb") as f:
245
+ result = vision_model.describe_with_prompt(f.read())
246
+ ```