diff --git a/app.py b/app.py index 89eeae1..460222f 100644 --- a/app.py +++ b/app.py @@ -60,5 +60,5 @@ def internal_server_error(e): return render_template('error.html', error='服务器内部错误'), 500 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) diff --git a/requirements.txt b/requirements.txt index 5b4731c..35d2da0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,16 +3,18 @@ Flask==2.0.1 Werkzeug==2.0.1 mysql-connector-python==8.0.27 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-cpu>=2.9.0; platform_system!="Darwin" or platform_machine!="arm64" # 其他系统 -# tensorflow-gpu>=2.9.0 # 如果有GPU,可以取消此注释 - -# 基础数据处理 -numpy>=1.20.0 +# 模型和数据处理 +tensorflow==2.19.0 # 使用当前已安装的版本 +tensorflow-io-gcs-filesystem==0.37.1 +numpy==2.0.2 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 @@ -20,9 +22,31 @@ python-dateutil==2.8.2 # 邮件服务 Flask-Mail==0.9.1 +blinker==1.9.0 # 工具类 python-dotenv==0.20.0 +requests==2.32.3 +six==1.17.0 # 生产部署 -gunicorn==20.1.0 \ No newline at end of file +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 \ No newline at end of file diff --git a/routes/__init__.py b/routes/__init__.py index 28372e0..adedc03 100644 --- a/routes/__init__.py +++ b/routes/__init__.py @@ -2,10 +2,18 @@ from flask import Blueprint # 导入各个路由模块 from routes.auth import auth -# 后续会添加其他路由模块 +from routes.classify import classify_bp # 创建注册蓝图的函数 def register_blueprints(app): """在Flask应用中注册所有蓝图""" # 认证相关路由,使用/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}") \ No newline at end of file diff --git a/routes/classify.py b/routes/classify.py index 820a952..7ac0f98 100644 --- a/routes/classify.py +++ b/routes/classify.py @@ -539,30 +539,30 @@ def download_multiple_documents(): # 检查用户是否登录 if 'user_id' not in session: return jsonify({"success": False, "error": "请先登录"}), 401 - + user_id = session['user_id'] - + # 获取请求数据 data = request.get_json() if not data or 'document_ids' not in data: return jsonify({"success": False, "error": "缺少必要参数"}), 400 - + document_ids = data['document_ids'] if not isinstance(document_ids, list) or not document_ids: return jsonify({"success": False, "error": "文档ID列表无效"}), 400 - + db = get_db() cursor = db.cursor(dictionary=True) - + try: # 创建临时目录用于存放zip文件 temp_dir = os.path.join(current_app.root_path, 'temp') os.makedirs(temp_dir, exist_ok=True) - + # 创建临时ZIP文件 zip_filename = f"documents_{int(time.time())}.zip" zip_path = os.path.join(temp_dir, zip_filename) - + # 查询所有符合条件的文档 placeholders = ', '.join(['%s'] * len(document_ids)) query = f""" @@ -573,17 +573,17 @@ def download_multiple_documents(): params = document_ids + [user_id] cursor.execute(query, params) documents = cursor.fetchall() - + if not documents: return jsonify({"success": False, "error": "没有找到符合条件的文档"}), 404 - + # 创建ZIP文件并添加文档 with zipfile.ZipFile(zip_path, 'w') as zipf: for doc in documents: if os.path.exists(doc['file_path']): # 添加文件到zip,使用原始文件名 zipf.write(doc['file_path'], arcname=doc['original_filename']) - + # 返回ZIP文件下载 return send_file( zip_path, @@ -591,11 +591,11 @@ def download_multiple_documents(): download_name=zip_filename, mimetype='application/zip' ) - - except Exception as e: + + except Exception as e: logger.error(f"下载多个文档时出错: {str(e)}") return jsonify({"success": False, "error": f"下载文档失败: {str(e)}"}), 500 - + finally: cursor.close() diff --git a/utils/db.py b/utils/db.py index a54245d..2dd56c5 100644 --- a/utils/db.py +++ b/utils/db.py @@ -1,6 +1,7 @@ import mysql.connector from mysql.connector import Error import config +from flask import g def get_db_connection(): """创建数据库连接""" @@ -20,3 +21,21 @@ def close_connection(conn): """关闭数据库连接""" if conn: 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) + \ No newline at end of file