9.23测试分段
This commit is contained in:
parent
5fb525186f
commit
d5b8a06322
@ -56,26 +56,6 @@ def create_logger():
|
|||||||
g.logger = logger
|
g.logger = logger
|
||||||
|
|
||||||
|
|
||||||
# @app.route('/upload', methods=['POST'])
|
|
||||||
# def zbparse():
|
|
||||||
# logger=g.logger
|
|
||||||
# file_url = validate_request()
|
|
||||||
# if isinstance(file_url, tuple): # Check if the returned value is an error response
|
|
||||||
# return file_url
|
|
||||||
# try:
|
|
||||||
# logger.info("starting parsing url:" + file_url)
|
|
||||||
# final_json_path, output_folder= download_and_process_file(file_url)
|
|
||||||
# if not final_json_path:
|
|
||||||
# return jsonify({'error': 'File processing failed'}), 500
|
|
||||||
# response = generate_response(final_json_path) # 先获取响应内容
|
|
||||||
# # remove_directory(output_folder) # 然后删除文件夹
|
|
||||||
# return response # 最后返回获取的响应
|
|
||||||
# except Exception as e:
|
|
||||||
# logger.error('Exception occurred: ' + str(e)) # 使用全局 logger 记录
|
|
||||||
# return jsonify({'error': str(e)}), 500
|
|
||||||
|
|
||||||
|
|
||||||
# 流式
|
|
||||||
@app.route('/upload', methods=['POST'])
|
@app.route('/upload', methods=['POST'])
|
||||||
def zbparse():
|
def zbparse():
|
||||||
logger=g.logger
|
logger=g.logger
|
||||||
@ -84,48 +64,68 @@ def zbparse():
|
|||||||
return file_url
|
return file_url
|
||||||
try:
|
try:
|
||||||
logger.info("starting parsing url:" + file_url)
|
logger.info("starting parsing url:" + file_url)
|
||||||
return Response(stream_with_context(process_and_stream(file_url)), content_type='text/event-stream')
|
final_json_path, output_folder= download_and_process_file(file_url)
|
||||||
|
if not final_json_path:
|
||||||
|
return jsonify({'error': 'File processing failed'}), 500
|
||||||
|
response = generate_response(final_json_path) # 先获取响应内容
|
||||||
|
# remove_directory(output_folder) # 然后删除文件夹
|
||||||
|
return response # 最后返回获取的响应
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Exception occurred: ' + str(e))
|
logger.error('Exception occurred: ' + str(e)) # 使用全局 logger 记录
|
||||||
return jsonify({'error': str(e)}), 500
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
# 流式
|
||||||
|
# @app.route('/upload', methods=['POST'])
|
||||||
|
# def zbparse():
|
||||||
|
# logger = g.logger
|
||||||
|
# file_url = validate_request()
|
||||||
|
# if isinstance(file_url, tuple): # Check if the returned value is an error response
|
||||||
|
# return file_url
|
||||||
|
# try:
|
||||||
|
# logger.info("starting parsing url:" + file_url)
|
||||||
|
# return Response(stream_with_context(process_and_stream(file_url)), content_type='text/event-stream')
|
||||||
|
# except Exception as e:
|
||||||
|
# logger.error('Exception occurred: ' + str(e))
|
||||||
|
# return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
#分段返回
|
#分段返回
|
||||||
def process_and_stream(file_url):
|
# def process_and_stream(file_url):
|
||||||
logger = g.logger
|
# logger = g.logger
|
||||||
unique_id = g.unique_id
|
# unique_id = g.unique_id
|
||||||
output_folder = f"flask_app/static/output/{unique_id}" # 直接使用全局 unique_id 构建路径
|
# output_folder = f"flask_app/static/output/{unique_id}" # 直接使用全局 unique_id 构建路径
|
||||||
filename = "ztbfile"
|
# filename = "ztbfile"
|
||||||
downloaded_filename = os.path.join(output_folder, filename)
|
# downloaded_filename = os.path.join(output_folder, filename)
|
||||||
|
#
|
||||||
downloaded_filepath, file_type = download_file(file_url, downloaded_filename)
|
# downloaded_filepath, file_type = download_file(file_url, downloaded_filename)
|
||||||
|
#
|
||||||
if downloaded_filepath is None or file_type == 3:
|
# if downloaded_filepath is None or file_type == 3:
|
||||||
logger.error("Unsupported file type or failed to download file")
|
# logger.error("Unsupported file type or failed to download file")
|
||||||
error_response = {
|
# error_response = {
|
||||||
'message': 'File processing failed',
|
# 'message': 'File processing failed',
|
||||||
'filename': None,
|
# 'filename': None,
|
||||||
'data': json.dumps({'error': 'File processing failed'})
|
# 'data': json.dumps({'error': 'File processing failed'})
|
||||||
}
|
# }
|
||||||
yield f"data: {json.dumps(error_response)}\n\n"
|
# yield f"data: {json.dumps(error_response)}\n\n"
|
||||||
return
|
# return
|
||||||
|
#
|
||||||
logger.info("Local file path: " + downloaded_filepath)
|
# logger.info("Local file path: " + downloaded_filepath)
|
||||||
|
#
|
||||||
for data in main_processing(output_folder, downloaded_filepath, file_type, unique_id):
|
# for data in main_processing(output_folder, downloaded_filepath, file_type, unique_id):
|
||||||
response = {
|
# response = {
|
||||||
'message': 'Processing',
|
# 'message': 'Processing',
|
||||||
'filename': os.path.basename(downloaded_filepath),
|
# 'filename': os.path.basename(downloaded_filepath),
|
||||||
'data': data
|
# 'data': data
|
||||||
}
|
# }
|
||||||
yield f"data: {json.dumps(response)}\n\n"
|
# yield f"data: {json.dumps(response)}\n\n"
|
||||||
|
#
|
||||||
final_response = {
|
# final_response = {
|
||||||
'message': 'File uploaded and processed successfully',
|
# 'message': 'File uploaded and processed successfully',
|
||||||
'filename': os.path.basename(downloaded_filepath),
|
# 'filename': os.path.basename(downloaded_filepath),
|
||||||
'data': 'END'
|
# 'data': 'END'
|
||||||
}
|
# }
|
||||||
yield f"data: {json.dumps(final_response)}\n\n"
|
# yield f"data: {json.dumps(final_response)}\n\n"
|
||||||
|
|
||||||
|
|
||||||
def validate_request():
|
def validate_request():
|
||||||
|
@ -101,7 +101,6 @@ def combine_evaluation_standards(truncate2):
|
|||||||
user_query_2 = (
|
user_query_2 = (
|
||||||
"根据该文档中的评标办法前附表,请你列出该文件的技术标,商务标,投标报价评审标准以及它们对应的具体评分要求,若对应内容中存在其他信息,在键名如'技术标'中新增子键名'备注'存放该信息。如果评分内容不是这3个,则返回文档中给定的评分内容以及它的评分要求,都以json的格式返回结果。请不要回答有关形式、资格、响应性评审标准的内容")
|
"根据该文档中的评标办法前附表,请你列出该文件的技术标,商务标,投标报价评审标准以及它们对应的具体评分要求,若对应内容中存在其他信息,在键名如'技术标'中新增子键名'备注'存放该信息。如果评分内容不是这3个,则返回文档中给定的评分内容以及它的评分要求,都以json的格式返回结果。请不要回答有关形式、资格、响应性评审标准的内容")
|
||||||
evaluation_res = qianwen_long(file_id, user_query_2)
|
evaluation_res = qianwen_long(file_id, user_query_2)
|
||||||
print(evaluation_res)
|
|
||||||
target_values1 = ['技术标','技术部分','设计', '实施']
|
target_values1 = ['技术标','技术部分','设计', '实施']
|
||||||
# target_values2=['投标报价','商务标','商务部分','报价部分','业绩','信誉','分值','计算公式','信用','人员','资格','奖项','认证','荣誉']
|
# target_values2=['投标报价','商务标','商务部分','报价部分','业绩','信誉','分值','计算公式','信用','人员','资格','奖项','认证','荣誉']
|
||||||
# update_json=combine_technical_and_business(clean_json_string(evaluation_res),target_values1,target_values2)
|
# update_json=combine_technical_and_business(clean_json_string(evaluation_res),target_values1,target_values2)
|
||||||
@ -110,6 +109,6 @@ def combine_evaluation_standards(truncate2):
|
|||||||
return evaluation_combined_res
|
return evaluation_combined_res
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
truncate2="C:\\Users\\Administrator\\Desktop\\招标文件\\招标04_evaluation_method.pdf"
|
truncate2="C:\\Users\\Administrator\\Desktop\\招标文件\\招标test文件夹\\zbtest20_evaluation_method.pdf"
|
||||||
res=combine_evaluation_standards(truncate2)
|
res=combine_evaluation_standards(truncate2)
|
||||||
print(res)
|
print(res)
|
@ -29,13 +29,13 @@ def combine_review_standards(truncate1,truncate3,knowledge_name,truncate0_jsonpa
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
input_file="C:\\Users\\Administrator\\Desktop\\招标文件\\招标test文件夹\\zbtest11.pdf"
|
input_file="C:\\Users\\Administrator\\Desktop\\fsdownload\\4a611a66-0dac-4daf-b365-c6167c5b8c8d\\ztbfile.pdf"
|
||||||
output_folder = "C:\\Users\\Administrator\\Desktop\\招标文件\\招标test文件夹"
|
output_folder = "C:\\Users\\Administrator\\Desktop\\fsdownload\\4a611a66-0dac-4daf-b365-c6167c5b8c8d"
|
||||||
# truncate0 = os.path.join(output_folder, "zbtest20_tobidders_notice_table.pdf")
|
# truncate0 = os.path.join(output_folder, "zbtest20_tobidders_notice_table.pdf")
|
||||||
truncate2=os.path.join(output_folder,"zbtest20_tobidders_notice.pdf")
|
truncate2=os.path.join(output_folder,"ztbfile_tobidders_notice.pdf")
|
||||||
knowledge_name="zbtest20"
|
knowledge_name="zbtest20"
|
||||||
truncate1=os.path.join(output_folder,"zbtest20_evaluation_method.pdf")
|
truncate1=os.path.join(output_folder,"ztbfile_evaluation_method.pdf")
|
||||||
truncate3=os.path.join(output_folder,"zbtest20_qualification.pdf")
|
truncate3=os.path.join(output_folder,"ztbfile_qualification.pdf")
|
||||||
clause_path = convert_clause_to_json(truncate2, output_folder)
|
clause_path = convert_clause_to_json(truncate2, output_folder)
|
||||||
truncate0_jsonpath = os.path.join(output_folder, "truncate_output.json")
|
truncate0_jsonpath = os.path.join(output_folder, "truncate_output.json")
|
||||||
res=combine_review_standards(truncate1,truncate3, knowledge_name,truncate0_jsonpath,clause_path,input_file,output_folder)
|
res=combine_review_standards(truncate1,truncate3, knowledge_name,truncate0_jsonpath,clause_path,input_file,output_folder)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user