zbparse/flask_app/货物标/基础信息解析货物标版.py

84 lines
5.2 KiB
Python
Raw Normal View History

2024-10-15 20:57:58 +08:00
# -*- encoding:utf-8 -*-
2024-10-14 17:13:11 +08:00
import json
2024-10-15 20:57:58 +08:00
import threading
import time
2024-10-30 20:41:19 +08:00
import concurrent.futures
2024-12-12 16:06:20 +08:00
from flask_app.general.json_utils import clean_json_string, add_outer_key
2025-01-02 15:35:38 +08:00
from flask_app.general.通用功能函数 import process_judge_questions, aggregate_basic_info
2024-10-22 10:06:22 +08:00
from flask_app.general.多线程提问 import read_questions_from_file, multi_threading
from flask_app.general.通义千问long import upload_file
2025-01-02 15:35:38 +08:00
from flask_app.工程标.判断是否分包等 import merge_json_to_list
from flask_app.general.投标人须知正文提取指定内容 import extract_from_notice
2024-10-15 20:57:58 +08:00
from flask_app.货物标.提取采购需求main import fetch_procurement_reqs
2024-10-14 17:13:11 +08:00
2024-11-04 17:13:06 +08:00
def get_base_info(merged_baseinfo_path,clause_path):
file_id = upload_file(merged_baseinfo_path)
2024-12-23 16:00:23 +08:00
baseinfo_file_path='flask_app/static/提示词/基本信息货物标.txt'
# baseinfo_file_path = r'D:\flask_project\flask_app\static\提示词\基本信息货物标.txt'
2024-10-15 20:57:58 +08:00
questions = read_questions_from_file(baseinfo_file_path)
2024-11-01 14:39:39 +08:00
more_query = "请你根据招标文件信息,回答以下问题:是否组织踏勘现场?是否召开投标预备会(或投标答疑会)?是否退还投标文件?是否允许分包? 是否需要递交投标保证金或磋商保证金是否需要提交履约保证金或履约担保是否有招标代理服务费或中标、成交服务费或采购代理服务费请按json格式给我提供信息键名分别为'是否组织踏勘现场','是否召开投标预备会'(或'是否召开投标答疑会','是否退还投标文件',是否允许分包','是否递交投标保证金'(或'是否递交磋商保证金','是否提交履约保证金','是否有招标代理服务费',键值仅限于'','','未知',若存在矛盾信息,请回答'未知'"
2024-10-15 20:57:58 +08:00
questions.append(more_query)
baseinfo_results = multi_threading(questions, "", file_id, 2) # 1代表使用百炼rag 2代表使用qianwen-long
2024-10-17 15:33:58 +08:00
baseinfo_list = [clean_json_string(res) for _, res in baseinfo_results] if baseinfo_results else []
chosen_numbers, merged = merge_json_to_list(baseinfo_list.pop())
2024-10-15 20:57:58 +08:00
baseinfo_list.append(merged)
2024-12-30 17:32:24 +08:00
judge_file_path = 'flask_app/static/提示词/是否相关问题.txt'
# judge_file_path =r'D:\flask_project\flask_app\static\提示词\是否相关问题.txt'
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
2024-10-30 20:41:19 +08:00
# 提交两个任务
2024-12-17 14:47:19 +08:00
future1 = executor.submit(process_judge_questions, judge_file_path, chosen_numbers, file_id,
2024-10-30 20:41:19 +08:00
baseinfo_list)
2024-11-04 17:13:06 +08:00
future2 = executor.submit(extract_from_notice, merged_baseinfo_path, clause_path, 3) # 新增的多线程任务
2024-10-30 20:41:19 +08:00
# 等待两个任务完成并获取结果
future1.result() # process_judge_questions 直接修改 baseinfo_list不需要返回值
2024-10-31 15:03:32 +08:00
rebidding_situation = future2.result()
2024-12-12 16:06:20 +08:00
update_json = add_outer_key(rebidding_situation, "重新招标、不再招标和终止招标")
2024-10-31 15:03:32 +08:00
baseinfo_list.append(update_json)
2024-10-15 20:57:58 +08:00
return baseinfo_list
2024-11-16 16:14:53 +08:00
def combine_basic_info(merged_baseinfo_path, procurement_path,clause_path,invalid_path):
2024-10-15 20:57:58 +08:00
baseinfo_list = []
temp_list = []
procurement_reqs = {}
# 定义一个线程函数来获取基础信息
def get_base_info_thread():
nonlocal temp_list
2024-11-04 17:13:06 +08:00
temp_list = get_base_info(merged_baseinfo_path,clause_path)
2024-10-15 20:57:58 +08:00
# 定义一个线程函数来获取采购需求
def fetch_procurement_reqs_thread():
nonlocal procurement_reqs
2024-11-16 16:14:53 +08:00
procurement_reqs = fetch_procurement_reqs(procurement_path,invalid_path)
2024-10-15 20:57:58 +08:00
# 创建并启动获取基础信息的线程
thread1 = threading.Thread(target=get_base_info_thread)
thread1.start()
# 等待一秒后启动获取采购需求的线程
time.sleep(1)
2024-10-24 11:29:31 +08:00
thread2 = threading.Thread(target=fetch_procurement_reqs_thread)
thread2.start()
2024-10-15 20:57:58 +08:00
# 等待两个线程都完成
thread1.join()
2024-10-24 11:29:31 +08:00
thread2.join()
2024-10-15 20:57:58 +08:00
# 合并结果
baseinfo_list += temp_list # temp_list 是一个列表
2024-10-24 11:29:31 +08:00
baseinfo_list.append(procurement_reqs) # procurement_reqs 是一个字典
2025-01-02 15:35:38 +08:00
aggregated_baseinfo = aggregate_basic_info(baseinfo_list,'goods')
2024-10-15 20:57:58 +08:00
return {"基础信息": aggregated_baseinfo}
2024-10-14 17:13:11 +08:00
if __name__ == "__main__":
2024-10-15 20:57:58 +08:00
start_time=time.time()
2024-10-22 21:02:54 +08:00
# baseinfo_file_path = "C:\\Users\\Administrator\\Desktop\\货物标\\truncate_all\\ztbfile_merged_baseinfo\\ztbfile_merged_baseinfo_3-31.pdf"
2024-12-23 15:47:41 +08:00
merged_baseinfo_path=r"D:\flask_project\flask_app\static\output\output1\eabefc28-142f-4bb5-b1be-e86e43bb87b5\invalid_del.docx"
2024-10-15 20:57:58 +08:00
# procurement_file_path = "C:\\Users\\Administrator\\Desktop\\fsdownload\\b4601ea1-f087-4fa2-88ae-336ad4d8e1e9\\tmp\\ztbfile_procurement.pdf"
2024-12-18 12:26:27 +08:00
procurement_file_path = r"D:\flask_project\flask_app\static\output\output1\83ae3e35-9136-4402-a74f-01d7adfcbb73\invalid_added.docx"
2024-10-31 15:03:32 +08:00
clause_path='D:\\flask_project\\flask_app\\static\\output\\output1\\bf225a5e-16d0-45c8-8c19-54a1a94cf3e2\\clause1.json'
2024-12-23 15:47:41 +08:00
# res = combine_basic_info(merged_baseinfo_path, procurement_file_path,clause_path)
res=get_base_info(merged_baseinfo_path,"")
2024-10-31 15:03:32 +08:00
print("------------------------------------")
2024-10-15 20:57:58 +08:00
print(json.dumps(res, ensure_ascii=False, indent=4))
end_time=time.time()
print("elasped time:"+str(end_time-start_time))