lyg
2025-03-04 58486e5e6e9c423a999d495a6446021aa808f32f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from lang_flow import LangFlow
from markitdown import MarkItDown
 
from doc_to_docx import doc_to_docx
 
 
def process_docs(directory):
    # 遍历目录下的所有文件
    for filename in os.listdir(directory):
        # 判断是否为 doc 文件
        if filename.endswith(".doc"):
            # 转换为 docx
            doc_to_docx(directory + filename, directory + filename.replace(".doc", ".docx"))
 
 
md = MarkItDown()
 
 
def to_markdown(dst_dir: str):
    text = ''
    # 遍历文件夹下的所有文件
    for file in os.listdir(dst_dir):
        # 判断是否为 docx 文件
        if file.endswith(".docx"):
            # 转换为 md
            result = md.convert(dst_dir + file)
            text += '\n\n' + result.text_content
    out_file = dst_dir + 'docs.md'
    with open(out_file, 'w', encoding='utf-8') as f:
        f.write(text)
    return out_file
 
 
# 1.解析文档
# 2.输入文档
# 3.启动LangFlow
def main():
    # doc_dir = "D:\\workspace\\PythonProjects\\KnowledgeBase\\doc\\"
    # 处理文档
    # process_docs(doc_dir)
    # 文档转换为markdown
    # md_file = to_markdown(doc_dir)
 
    md_file = 'D:\\workspace\\PythonProjects\\KnowledgeBase\\doc\\test.md'
    # 启动大模型处理流程
    ret_text = LangFlow([md_file]).run()
    # 保存结果
    # with open('D:\\workspace\\PythonProjects\\KnowledgeBase\\doc\\test.text', 'w', encoding='utf-8') as f:
    #     f.write(ret_text)
 
if __name__ == '__main__':
    main()