File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,12 +57,13 @@ Bella-Knowledge地址:https://github.com/LianjiaTech/bella-knowledge
57571 . 安装依赖
5858
5959 ``` shell
60- pip install document_parser
60+ pip install bella-domify
6161 ```
6262
63632 . 配置
6464
6565 ``` python
66+ # ImageStorageProvider是个抽象类,需要自己实现图片的存储,内部有upload和down方法
6667 parser_config = ParserConfig(image_provider = ImageStorageProvider(),
6768 ocr_model_name = " gtp-4o" ,
6869 # 是否开启OCR能力
@@ -75,11 +76,13 @@ Bella-Knowledge地址:https://github.com/LianjiaTech/bella-knowledge
7576
76773 . 执行解析
7778 ``` python
78- converter = Converter(stream = stream) # 以文件流的形式传入
79+ # Converter类型有PDFConverter、XlsExcelConverter、XlsxExcelConverter、TxtConverter等
80+ converter = PDFConverter(stream = stream) # 以文件流的形式传入
7981 dom_tree = converter.dom_tree_parse(
8082 remove_watermark = True , # 是否开启去水印
8183 parse_stream_table = False # 是否解析流式表格
8284 )
85+ print (dom_tree)
8386 ```
8487
8588### 服务化运行
Original file line number Diff line number Diff line change @@ -49,11 +49,12 @@ The following environment variables need to be set:
4949
50501 . Install Dependencies
5151 ``` shell
52- pip install document_parser
52+ pip install bella-domify
5353 ```
5454
55552 . Configuration
5656 ``` python
57+ # ImageStorageProvider is ABC, you can implement your own image storage provider according to your business needs
5758 parser_config = ParserConfig(image_provider = ImageStorageProvider(),
5859 ocr_model_name = " gtp-4o" ,
5960 # Whether to enable OCR capability
@@ -66,11 +67,13 @@ The following environment variables need to be set:
6667
67683 . Execute Parsing
6869 ``` python
69- converter = Converter(stream = stream) # Pass in as file stream
70- dom_tree = converter.dom_tree_parse(
70+ # Converter:PDFConverter、XlsExcelConverter、XlsxExcelConverter、TxtConverter etc.
71+ converter = PDFConverter(stream = stream) # Pass in as bytes stream
72+ dom_tree = converter.dom_tree_parse(
7173 remove_watermark = True , # Whether to enable watermark removal
72- parse_stream_table = False # Whether to parse streaming tables
74+ parse_stream_table = False # Whether to parse streaming tables
7375 )
76+ print (dom_tree)
7477 ```
7578
7679### Running as a Service
Original file line number Diff line number Diff line change @@ -42,25 +42,28 @@ def load_long_description(fname):
4242
4343
4444def load_requirements (fname ):
45- try :
46- # pip >= 10.0
47- from pip ._internal .req import parse_requirements
48- except ImportError :
49- # pip < 10.0
50- from pip .req import parse_requirements
45+ """纯文件读取,不依赖 pip"""
46+ if not os .path .isfile (fname ):
47+ return [] # 文件不存在就当成空依赖
5148
52- reqs = parse_requirements (fname , session = False )
53- try :
54- requirements = [str (ir .requirement ) for ir in reqs ]
55- except AttributeError :
56- requirements = [str (ir .req ) for ir in reqs ]
49+ with open (fname , encoding = "utf-8" ) as f :
50+ lines = f .readlines ()
5751
58- return requirements
52+ reqs = []
53+ for line in lines :
54+ line = line .strip ()
55+ if line == "" or line .startswith ("#" ): # 去掉空行和注释
56+ continue
57+ # 简单处理 --find-links 等命令行参数(如果有)
58+ if line .startswith ("-" ):
59+ continue
60+ reqs .append (line )
61+ return reqs
5962
6063
6164if __name__ == "__main__" :
6265 setup (
63- name = "document_parser " ,
66+ name = "bella-domify " ,
6467 version = get_version ("version.txt" ),
6568 keywords = ["document-doc_parser" ],
6669 description = DESCRIPTION ,
You can’t perform that action at this time.
0 commit comments