|
@@ -6,6 +6,7 @@ import ollama
|
|
|
import json
|
|
|
import datetime
|
|
|
import uuid
|
|
|
+import os
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
@@ -24,8 +25,13 @@ conn = psycopg2.connect(
|
|
|
port="5432"
|
|
|
)
|
|
|
|
|
|
+# 文件保存路径
|
|
|
+UPLOAD_FOLDER = 'data/audio'
|
|
|
+os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
|
|
|
|
# 后台接口
|
|
|
+
|
|
|
+
|
|
|
@app.route("/")
|
|
|
def home():
|
|
|
return render_template('index.html')
|
|
@@ -37,6 +43,30 @@ def home():
|
|
|
def hello():
|
|
|
return "Hello, World!"
|
|
|
|
|
|
+# 文件上传
|
|
|
+
|
|
|
+
|
|
|
+@app.route('/upload', methods=['POST'])
|
|
|
+def upload_file():
|
|
|
+ if 'file' not in request.files:
|
|
|
+ return jsonify({"error": "No file part in the request"}), 400
|
|
|
+
|
|
|
+ file = request.files['file']
|
|
|
+
|
|
|
+ if file.filename == '':
|
|
|
+ return jsonify({"error": "No file selected for uploading"}), 400
|
|
|
+
|
|
|
+ # 生成UUID文件名
|
|
|
+ file_ext = os.path.splitext(file.filename)[1]
|
|
|
+ filename = f"{uuid.uuid4()}{file_ext}"
|
|
|
+
|
|
|
+ # 保存文件
|
|
|
+ file_path = os.path.join(UPLOAD_FOLDER, filename)
|
|
|
+ file.save(file_path)
|
|
|
+
|
|
|
+ return jsonify({"msg": "上传成功", "code": 200, "filename": filename}), 200
|
|
|
+
|
|
|
+
|
|
|
# 接收消息,大模型解析
|
|
|
|
|
|
|