success
This commit is contained in:
parent
f434b83090
commit
a8a0beb277
2
app.py
2
app.py
@ -60,5 +60,5 @@ def internal_server_error(e):
|
|||||||
return render_template('error.html', error='服务器内部错误'), 500
|
return render_template('error.html', error='服务器内部错误'), 500
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, host='0.0.0.0', port=5010)
|
app.run(debug=True, host='0.0.0.0', port=5009)
|
||||||
|
|
||||||
|
@ -3,16 +3,18 @@ Flask==2.0.1
|
|||||||
Werkzeug==2.0.1
|
Werkzeug==2.0.1
|
||||||
mysql-connector-python==8.0.27
|
mysql-connector-python==8.0.27
|
||||||
bcrypt==3.2.0
|
bcrypt==3.2.0
|
||||||
|
itsdangerous==2.2.0
|
||||||
|
Jinja2==3.1.6
|
||||||
|
MarkupSafe==3.0.2
|
||||||
|
|
||||||
# 模型和数据处理 - 系统适配版本
|
# 模型和数据处理
|
||||||
tensorflow-macos>=2.9.0; platform_system=="Darwin" and platform_machine=="arm64" # Mac M1/M2
|
tensorflow==2.19.0 # 使用当前已安装的版本
|
||||||
tensorflow-cpu>=2.9.0; platform_system!="Darwin" or platform_machine!="arm64" # 其他系统
|
tensorflow-io-gcs-filesystem==0.37.1
|
||||||
# tensorflow-gpu>=2.9.0 # 如果有GPU,可以取消此注释
|
numpy==2.0.2
|
||||||
|
|
||||||
# 基础数据处理
|
|
||||||
numpy>=1.20.0
|
|
||||||
jieba==0.42.1
|
jieba==0.42.1
|
||||||
scikit-learn>=1.0.0
|
scikit-learn==1.6.1
|
||||||
|
scipy==1.13.1
|
||||||
|
h5py==3.13.0
|
||||||
|
|
||||||
# 文件处理
|
# 文件处理
|
||||||
rarfile==4.0
|
rarfile==4.0
|
||||||
@ -20,9 +22,31 @@ python-dateutil==2.8.2
|
|||||||
|
|
||||||
# 邮件服务
|
# 邮件服务
|
||||||
Flask-Mail==0.9.1
|
Flask-Mail==0.9.1
|
||||||
|
blinker==1.9.0
|
||||||
|
|
||||||
# 工具类
|
# 工具类
|
||||||
python-dotenv==0.20.0
|
python-dotenv==0.20.0
|
||||||
|
requests==2.32.3
|
||||||
|
six==1.17.0
|
||||||
|
|
||||||
# 生产部署
|
# 生产部署
|
||||||
gunicorn==20.1.0
|
gunicorn==20.1.0
|
||||||
|
|
||||||
|
# TensorFlow依赖
|
||||||
|
absl-py==2.1.0
|
||||||
|
astunparse==1.6.3
|
||||||
|
flatbuffers==25.2.10
|
||||||
|
gast==0.6.0
|
||||||
|
google-pasta==0.2.0
|
||||||
|
grpcio==1.71.0
|
||||||
|
keras==3.9.0
|
||||||
|
markdown==3.7
|
||||||
|
ml_dtypes==0.5.1
|
||||||
|
opt_einsum==3.4.0
|
||||||
|
packaging==24.2
|
||||||
|
protobuf==5.29.3
|
||||||
|
tensorboard==2.19.0
|
||||||
|
tensorboard-data-server==0.7.2
|
||||||
|
termcolor==2.5.0
|
||||||
|
typing_extensions==4.12.2
|
||||||
|
wrapt==1.17.2
|
@ -2,10 +2,18 @@ from flask import Blueprint
|
|||||||
|
|
||||||
# 导入各个路由模块
|
# 导入各个路由模块
|
||||||
from routes.auth import auth
|
from routes.auth import auth
|
||||||
# 后续会添加其他路由模块
|
from routes.classify import classify_bp
|
||||||
|
|
||||||
# 创建注册蓝图的函数
|
# 创建注册蓝图的函数
|
||||||
def register_blueprints(app):
|
def register_blueprints(app):
|
||||||
"""在Flask应用中注册所有蓝图"""
|
"""在Flask应用中注册所有蓝图"""
|
||||||
# 认证相关路由,使用/auth前缀
|
# 认证相关路由,使用/auth前缀
|
||||||
app.register_blueprint(auth, url_prefix='/auth')
|
app.register_blueprint(auth, url_prefix='/auth')
|
||||||
|
|
||||||
|
# 分类相关路由,使用/api/classify前缀
|
||||||
|
app.register_blueprint(classify_bp) # classify_bp已经在定义时设置了url_prefix='/api/classify'
|
||||||
|
|
||||||
|
# 打印所有注册的路由(调试用,可选)
|
||||||
|
print("已注册的路由:")
|
||||||
|
for rule in app.url_map.iter_rules():
|
||||||
|
print(f"{rule.endpoint}: {rule.rule}")
|
@ -539,30 +539,30 @@ def download_multiple_documents():
|
|||||||
# 检查用户是否登录
|
# 检查用户是否登录
|
||||||
if 'user_id' not in session:
|
if 'user_id' not in session:
|
||||||
return jsonify({"success": False, "error": "请先登录"}), 401
|
return jsonify({"success": False, "error": "请先登录"}), 401
|
||||||
|
|
||||||
user_id = session['user_id']
|
user_id = session['user_id']
|
||||||
|
|
||||||
# 获取请求数据
|
# 获取请求数据
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if not data or 'document_ids' not in data:
|
if not data or 'document_ids' not in data:
|
||||||
return jsonify({"success": False, "error": "缺少必要参数"}), 400
|
return jsonify({"success": False, "error": "缺少必要参数"}), 400
|
||||||
|
|
||||||
document_ids = data['document_ids']
|
document_ids = data['document_ids']
|
||||||
if not isinstance(document_ids, list) or not document_ids:
|
if not isinstance(document_ids, list) or not document_ids:
|
||||||
return jsonify({"success": False, "error": "文档ID列表无效"}), 400
|
return jsonify({"success": False, "error": "文档ID列表无效"}), 400
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
cursor = db.cursor(dictionary=True)
|
cursor = db.cursor(dictionary=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 创建临时目录用于存放zip文件
|
# 创建临时目录用于存放zip文件
|
||||||
temp_dir = os.path.join(current_app.root_path, 'temp')
|
temp_dir = os.path.join(current_app.root_path, 'temp')
|
||||||
os.makedirs(temp_dir, exist_ok=True)
|
os.makedirs(temp_dir, exist_ok=True)
|
||||||
|
|
||||||
# 创建临时ZIP文件
|
# 创建临时ZIP文件
|
||||||
zip_filename = f"documents_{int(time.time())}.zip"
|
zip_filename = f"documents_{int(time.time())}.zip"
|
||||||
zip_path = os.path.join(temp_dir, zip_filename)
|
zip_path = os.path.join(temp_dir, zip_filename)
|
||||||
|
|
||||||
# 查询所有符合条件的文档
|
# 查询所有符合条件的文档
|
||||||
placeholders = ', '.join(['%s'] * len(document_ids))
|
placeholders = ', '.join(['%s'] * len(document_ids))
|
||||||
query = f"""
|
query = f"""
|
||||||
@ -573,17 +573,17 @@ def download_multiple_documents():
|
|||||||
params = document_ids + [user_id]
|
params = document_ids + [user_id]
|
||||||
cursor.execute(query, params)
|
cursor.execute(query, params)
|
||||||
documents = cursor.fetchall()
|
documents = cursor.fetchall()
|
||||||
|
|
||||||
if not documents:
|
if not documents:
|
||||||
return jsonify({"success": False, "error": "没有找到符合条件的文档"}), 404
|
return jsonify({"success": False, "error": "没有找到符合条件的文档"}), 404
|
||||||
|
|
||||||
# 创建ZIP文件并添加文档
|
# 创建ZIP文件并添加文档
|
||||||
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
||||||
for doc in documents:
|
for doc in documents:
|
||||||
if os.path.exists(doc['file_path']):
|
if os.path.exists(doc['file_path']):
|
||||||
# 添加文件到zip,使用原始文件名
|
# 添加文件到zip,使用原始文件名
|
||||||
zipf.write(doc['file_path'], arcname=doc['original_filename'])
|
zipf.write(doc['file_path'], arcname=doc['original_filename'])
|
||||||
|
|
||||||
# 返回ZIP文件下载
|
# 返回ZIP文件下载
|
||||||
return send_file(
|
return send_file(
|
||||||
zip_path,
|
zip_path,
|
||||||
@ -591,11 +591,11 @@ def download_multiple_documents():
|
|||||||
download_name=zip_filename,
|
download_name=zip_filename,
|
||||||
mimetype='application/zip'
|
mimetype='application/zip'
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"下载多个文档时出错: {str(e)}")
|
logger.error(f"下载多个文档时出错: {str(e)}")
|
||||||
return jsonify({"success": False, "error": f"下载文档失败: {str(e)}"}), 500
|
return jsonify({"success": False, "error": f"下载文档失败: {str(e)}"}), 500
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
19
utils/db.py
19
utils/db.py
@ -1,6 +1,7 @@
|
|||||||
import mysql.connector
|
import mysql.connector
|
||||||
from mysql.connector import Error
|
from mysql.connector import Error
|
||||||
import config
|
import config
|
||||||
|
from flask import g
|
||||||
|
|
||||||
def get_db_connection():
|
def get_db_connection():
|
||||||
"""创建数据库连接"""
|
"""创建数据库连接"""
|
||||||
@ -20,3 +21,21 @@ def close_connection(conn):
|
|||||||
"""关闭数据库连接"""
|
"""关闭数据库连接"""
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
# 添加与routes/classify.py兼容的函数名称
|
||||||
|
def get_db():
|
||||||
|
"""获取数据库连接 (与classify.py兼容)"""
|
||||||
|
if 'db' not in g:
|
||||||
|
g.db = get_db_connection()
|
||||||
|
return g.db
|
||||||
|
|
||||||
|
def close_db(e=None):
|
||||||
|
"""关闭数据库连接 (与classify.py兼容)"""
|
||||||
|
db = g.pop('db', None)
|
||||||
|
if db:
|
||||||
|
close_connection(db)
|
||||||
|
|
||||||
|
def init_app(app):
|
||||||
|
"""在Flask应用中注册数据库清理函数"""
|
||||||
|
app.teardown_appcontext(close_db)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user