init: RAG 知识库服务初始提交
- 后端 API(Flask + Gunicorn) - RAG 引擎(混合检索 + 云端 Reranker + 引用溯源) - 文档解析(MinerU + 多格式支持) - Docker 生产部署配置 - 排除前端项目、敏感配置、模型文件
This commit is contained in:
27
parsers/txt_parser.py
Normal file
27
parsers/txt_parser.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
TXT 文本解析器
|
||||
|
||||
简单的文本文件读取,支持 UTF-8 和 GBK 编码自动检测。
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def extract_text_from_txt(filepath):
|
||||
"""从TXT提取文本"""
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
except UnicodeDecodeError:
|
||||
# 尝试其他编码
|
||||
try:
|
||||
with open(filepath, 'r', encoding='gbk') as f:
|
||||
return f.read()
|
||||
except Exception as e:
|
||||
logger.error(f"TXT解析错误 {filepath}: {e}")
|
||||
return ""
|
||||
except Exception as e:
|
||||
print(f" TXT解析错误 {filepath}: {e}")
|
||||
return ""
|
||||
Reference in New Issue
Block a user