From d5b8a063228a008f564261d35c40ac6e7f809b86 Mon Sep 17 00:00:00 2001 From: zy123 <646228430@qq.com> Date: Mon, 23 Sep 2024 12:41:56 +0800 Subject: [PATCH] =?UTF-8?q?9.23=E6=B5=8B=E8=AF=95=E5=88=86=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flask_app/main/start_up.py | 116 ++++++++++++++--------------- flask_app/main/商务标技术标整合.py | 3 +- flask_app/main/资格审查模块.py | 10 +-- 3 files changed, 64 insertions(+), 65 deletions(-) diff --git a/flask_app/main/start_up.py b/flask_app/main/start_up.py index f4a3764..f66ec6d 100644 --- a/flask_app/main/start_up.py +++ b/flask_app/main/start_up.py @@ -56,76 +56,76 @@ def create_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']) def zbparse(): - logger = g.logger + 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') + 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.error('Exception occurred: ' + str(e)) # 使用全局 logger 记录 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): - logger = g.logger - unique_id = g.unique_id - output_folder = f"flask_app/static/output/{unique_id}" # 直接使用全局 unique_id 构建路径 - filename = "ztbfile" - downloaded_filename = os.path.join(output_folder, filename) - - downloaded_filepath, file_type = download_file(file_url, downloaded_filename) - - if downloaded_filepath is None or file_type == 3: - logger.error("Unsupported file type or failed to download file") - error_response = { - 'message': 'File processing failed', - 'filename': None, - 'data': json.dumps({'error': 'File processing failed'}) - } - yield f"data: {json.dumps(error_response)}\n\n" - return - - logger.info("Local file path: " + downloaded_filepath) - - for data in main_processing(output_folder, downloaded_filepath, file_type, unique_id): - response = { - 'message': 'Processing', - 'filename': os.path.basename(downloaded_filepath), - 'data': data - } - yield f"data: {json.dumps(response)}\n\n" - - final_response = { - 'message': 'File uploaded and processed successfully', - 'filename': os.path.basename(downloaded_filepath), - 'data': 'END' - } - yield f"data: {json.dumps(final_response)}\n\n" +# def process_and_stream(file_url): +# logger = g.logger +# unique_id = g.unique_id +# output_folder = f"flask_app/static/output/{unique_id}" # 直接使用全局 unique_id 构建路径 +# filename = "ztbfile" +# downloaded_filename = os.path.join(output_folder, filename) +# +# downloaded_filepath, file_type = download_file(file_url, downloaded_filename) +# +# if downloaded_filepath is None or file_type == 3: +# logger.error("Unsupported file type or failed to download file") +# error_response = { +# 'message': 'File processing failed', +# 'filename': None, +# 'data': json.dumps({'error': 'File processing failed'}) +# } +# yield f"data: {json.dumps(error_response)}\n\n" +# return +# +# logger.info("Local file path: " + downloaded_filepath) +# +# for data in main_processing(output_folder, downloaded_filepath, file_type, unique_id): +# response = { +# 'message': 'Processing', +# 'filename': os.path.basename(downloaded_filepath), +# 'data': data +# } +# yield f"data: {json.dumps(response)}\n\n" +# +# final_response = { +# 'message': 'File uploaded and processed successfully', +# 'filename': os.path.basename(downloaded_filepath), +# 'data': 'END' +# } +# yield f"data: {json.dumps(final_response)}\n\n" def validate_request(): diff --git a/flask_app/main/商务标技术标整合.py b/flask_app/main/商务标技术标整合.py index aa8bdc3..95bd058 100644 --- a/flask_app/main/商务标技术标整合.py +++ b/flask_app/main/商务标技术标整合.py @@ -101,7 +101,6 @@ def combine_evaluation_standards(truncate2): user_query_2 = ( "根据该文档中的评标办法前附表,请你列出该文件的技术标,商务标,投标报价评审标准以及它们对应的具体评分要求,若对应内容中存在其他信息,在键名如'技术标'中新增子键名'备注'存放该信息。如果评分内容不是这3个,则返回文档中给定的评分内容以及它的评分要求,都以json的格式返回结果。请不要回答有关形式、资格、响应性评审标准的内容") evaluation_res = qianwen_long(file_id, user_query_2) - print(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 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) print(res) \ No newline at end of file diff --git a/flask_app/main/资格审查模块.py b/flask_app/main/资格审查模块.py index 6a71fc1..53f801c 100644 --- a/flask_app/main/资格审查模块.py +++ b/flask_app/main/资格审查模块.py @@ -29,13 +29,13 @@ def combine_review_standards(truncate1,truncate3,knowledge_name,truncate0_jsonpa if __name__ == "__main__": - input_file="C:\\Users\\Administrator\\Desktop\\招标文件\\招标test文件夹\\zbtest11.pdf" - output_folder = "C:\\Users\\Administrator\\Desktop\\招标文件\\招标test文件夹" + input_file="C:\\Users\\Administrator\\Desktop\\fsdownload\\4a611a66-0dac-4daf-b365-c6167c5b8c8d\\ztbfile.pdf" + output_folder = "C:\\Users\\Administrator\\Desktop\\fsdownload\\4a611a66-0dac-4daf-b365-c6167c5b8c8d" # 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" - truncate1=os.path.join(output_folder,"zbtest20_evaluation_method.pdf") - truncate3=os.path.join(output_folder,"zbtest20_qualification.pdf") + truncate1=os.path.join(output_folder,"ztbfile_evaluation_method.pdf") + truncate3=os.path.join(output_folder,"ztbfile_qualification.pdf") clause_path = convert_clause_to_json(truncate2, output_folder) 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)