2.14 新增文件切分的单独接口以供测试
This commit is contained in:
parent
0aa507d465
commit
f4fba07aa0
@ -92,7 +92,6 @@ def local_file_2_url(file_path, url):
|
|||||||
print("format_change 文件上传成功")
|
print("format_change 文件上传成功")
|
||||||
receive_file_response = response.content.decode('utf-8')
|
receive_file_response = response.content.decode('utf-8')
|
||||||
receive_file_json = json.loads(receive_file_response)
|
receive_file_json = json.loads(receive_file_response)
|
||||||
print(receive_file_json)
|
|
||||||
receive_file_url = receive_file_json["data"]
|
receive_file_url = receive_file_json["data"]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
61
flask_app/routes/test_preprocess.py
Normal file
61
flask_app/routes/test_preprocess.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
from flask import Flask, request, jsonify, Blueprint, g
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
import time
|
||||||
|
|
||||||
|
from flask_app.general.format_change import download_file
|
||||||
|
from flask_app.routes.utils import validate_and_setup_logger
|
||||||
|
from flask_app.routes.货物标解析main import preprocess_files
|
||||||
|
|
||||||
|
|
||||||
|
test_process_bp = Blueprint('test_process', __name__)
|
||||||
|
@test_process_bp.route('/test_process', methods=['POST'])
|
||||||
|
@validate_and_setup_logger
|
||||||
|
def process_file():
|
||||||
|
logger = g.logger
|
||||||
|
output_folder = g.output_folder
|
||||||
|
try:
|
||||||
|
# 解析请求参数
|
||||||
|
data = request.json
|
||||||
|
file_url = data.get('file_url')
|
||||||
|
# 参数校验
|
||||||
|
if not file_url:
|
||||||
|
return jsonify({'error': 'Missing file_url parameter'}), 400
|
||||||
|
|
||||||
|
# 生成唯一文件名
|
||||||
|
file_ext = '.pdf'
|
||||||
|
filename = f"{uuid.uuid4().hex}{file_ext}"
|
||||||
|
file_path,file_type=download_file(file_url, filename)
|
||||||
|
print(file_path)
|
||||||
|
# 调用预处理函数
|
||||||
|
start_time = time.time()
|
||||||
|
result = preprocess_files(
|
||||||
|
output_folder=output_folder,
|
||||||
|
file_path=file_path,
|
||||||
|
file_type=file_type,
|
||||||
|
logger=logger
|
||||||
|
)
|
||||||
|
|
||||||
|
# 处理结果
|
||||||
|
if not result:
|
||||||
|
return jsonify({'error': 'File processing failed'}), 500
|
||||||
|
|
||||||
|
# 构造响应数据(根据实际需要调整返回字段)
|
||||||
|
response_data = {
|
||||||
|
'processing_time': f"{time.time() - start_time:.2f}s",
|
||||||
|
'result': {
|
||||||
|
'procurement_spec': result['procurement_path'],
|
||||||
|
'evaluation_method': result['evaluation_method_path'],
|
||||||
|
'qualification_docs': result['qualification_path'],
|
||||||
|
'notice_docs': result['notice_path'],
|
||||||
|
'clause_details': result['clause_path'],
|
||||||
|
'merged_baseinfo': result['merged_baseinfo_path']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonify(response_data), 200
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# app.logger.error(f"Processing error: {str(e)}")
|
||||||
|
return jsonify({'error': f'Internal server error: {str(e)}'}), 500
|
@ -113,7 +113,8 @@ def validate_and_setup_logger(f):
|
|||||||
'get_deviation': 'output3',
|
'get_deviation': 'output3',
|
||||||
'little_zbparse': 'output2',
|
'little_zbparse': 'output2',
|
||||||
'upload': 'output1',
|
'upload': 'output1',
|
||||||
'test_zbparse': 'test_output'
|
'test_zbparse': 'test_output',
|
||||||
|
'test_preprocess':'test_output'
|
||||||
}
|
}
|
||||||
subfolder = subfolder_map.get(blueprint, 'test_output')
|
subfolder = subfolder_map.get(blueprint, 'test_output')
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ from flask_app.routes.upload import upload_bp
|
|||||||
from flask_app.routes.test_zbparse import test_zbparse_bp
|
from flask_app.routes.test_zbparse import test_zbparse_bp
|
||||||
from flask_app.general.llm.清除file_id import delete_file_by_ids,read_file_ids
|
from flask_app.general.llm.清除file_id import delete_file_by_ids,read_file_ids
|
||||||
from flask_app.routes.judge_zbfile import judge_zbfile_bp
|
from flask_app.routes.judge_zbfile import judge_zbfile_bp
|
||||||
|
from flask_app.routes.test_preprocess import test_process_bp
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
@ -23,14 +23,7 @@ def create_app():
|
|||||||
app.register_blueprint(upload_bp)
|
app.register_blueprint(upload_bp)
|
||||||
app.register_blueprint(test_zbparse_bp)
|
app.register_blueprint(test_zbparse_bp)
|
||||||
app.register_blueprint(judge_zbfile_bp)
|
app.register_blueprint(judge_zbfile_bp)
|
||||||
|
app.register_blueprint(test_process_bp)
|
||||||
@app.teardown_request
|
|
||||||
def check_fd(exception=None):
|
|
||||||
logger = g.logger
|
|
||||||
end_fd = os.listdir('/proc/self/fd')
|
|
||||||
leaked = set(end_fd) - set(g.start_fd)
|
|
||||||
if leaked:
|
|
||||||
logger.info(f"潜在FD泄漏: {len(leaked)}个未关闭")
|
|
||||||
# @app.teardown_request
|
# @app.teardown_request
|
||||||
# def teardown_request(exception):
|
# def teardown_request(exception):
|
||||||
# # 接口请求之后都会执行该代码,做一些清理工作
|
# # 接口请求之后都会执行该代码,做一些清理工作
|
||||||
|
Loading…
x
Reference in New Issue
Block a user