59 lines
2.9 KiB
Python
59 lines
2.9 KiB
Python
import concurrent.futures
|
||
import json
|
||
import time
|
||
from flask_app.货物标.技术参数要求提取 import get_technical_requirements
|
||
from flask_app.general.通义千问long import upload_file
|
||
from flask_app.货物标.商务服务其他要求提取 import get_business_requirements
|
||
|
||
|
||
#获取采购清单
|
||
def fetch_procurement_reqs(procurement_path,procurement_docpath,invalid_path):
|
||
# 定义默认的 procurement_reqs 字典
|
||
DEFAULT_PROCUREMENT_REQS = {
|
||
"技术要求": "",
|
||
"商务要求": "",
|
||
"服务要求": "",
|
||
"其他要求": ""
|
||
}
|
||
# 如果 truncate_file 是空字符串,直接返回包含空字符串的字典
|
||
if not procurement_docpath:
|
||
return DEFAULT_PROCUREMENT_REQS.copy()
|
||
try:
|
||
# 上传文件并获取 file_id
|
||
file_id = upload_file(procurement_docpath)
|
||
|
||
# 使用 ThreadPoolExecutor 并行处理 get_technical_requirements 和 get_business_requirements
|
||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||
# 提交任务给线程池
|
||
future_technical = executor.submit(get_technical_requirements, file_id,invalid_path)
|
||
time.sleep(0.5)
|
||
future_business = executor.submit(get_business_requirements, procurement_path, file_id)
|
||
|
||
# 获取并行任务的结果
|
||
technical_requirements = future_technical.result()
|
||
business_requirements = future_business.result()
|
||
|
||
# 构建最终的嵌套结构,确保四个键平级
|
||
procurement_reqs = {
|
||
"技术要求": technical_requirements.get("技术要求", {}),
|
||
"商务要求": business_requirements.get("商务要求", {}),
|
||
"服务要求": business_requirements.get("服务要求", {}),
|
||
"其他要求": business_requirements.get("其他要求", {}),
|
||
}
|
||
|
||
return procurement_reqs
|
||
|
||
except Exception as e:
|
||
print(f"Error in fetch_procurement_reqs: {e}")
|
||
# 在出错时返回默认的包含空字符串的字典
|
||
return DEFAULT_PROCUREMENT_REQS.copy()
|
||
|
||
if __name__ == "__main__":
|
||
output_folder = "C:\\Users\\Administrator\\Desktop\\货物标\\货物标output"
|
||
# file_path="C:\\Users\\Administrator\\Desktop\\货物标\\output1\\2-招标文件(2020年广水市中小学教师办公电脑系统及多媒体“班班通”设备采购安装项目)_procurement.pdf"
|
||
procurement_path = "C:\\Users\\Administrator\\Desktop\\fsdownload\\a6168046-ad8c-43cb-8913-071ce7b248a1\\ztbfile_procurement.docx"
|
||
procurement_docpath="C:\\Users\\Administrator\\Desktop\\fsdownload\\a6168046-ad8c-43cb-8913-071ce7b248a1\\ztbfile_procurement.docx"
|
||
invalid_path="C:\\Users\\Administrator\\Desktop\\fsdownload\\a6168046-ad8c-43cb-8913-071ce7b248a1\\ztbfile.pdf"
|
||
res=fetch_procurement_reqs(procurement_path,procurement_docpath,invalid_path)
|
||
print(json.dumps(res, ensure_ascii=False, indent=4))
|