70 lines
2.0 KiB
Python
Executable File
70 lines
2.0 KiB
Python
Executable File
from flask import Blueprint, request, jsonify
|
||
|
||
from ai_demo import porcess_video
|
||
|
||
example_info_ai_bp = Blueprint('example_ai_info', __name__)
|
||
|
||
"""
|
||
API接口:添加example_info数据
|
||
接口路径:POST /api/example_info/ai
|
||
|
||
请求体示例:
|
||
{
|
||
"video_path": "/videos/test1.mp4"
|
||
}
|
||
|
||
字段说明:
|
||
- video_path (可选):字符串,视频文件路径
|
||
"""
|
||
|
||
@example_info_ai_bp.route('/api/example_info/ai', methods=['POST'])
|
||
def add_example_ai_info():
|
||
try:
|
||
data = request.get_json()
|
||
print("data:",data)
|
||
|
||
# 验证必需字段
|
||
if not data:
|
||
return jsonify({
|
||
"success": False,
|
||
"message": "请求数据不能为空"
|
||
}), 400
|
||
|
||
# 获取请求数据
|
||
video_path = data.get('video_path')
|
||
|
||
json_info,emotion_reg_list,emotion_score_list=porcess_video(video_path)
|
||
# 构建SQL语句
|
||
emotion_state = "happy"
|
||
confidence = 0.1
|
||
flag = False
|
||
if len(emotion_reg_list) > 0:
|
||
emotion_state = emotion_reg_list[0]
|
||
flag = True
|
||
|
||
if len(emotion_score_list) > 0:
|
||
confidence = emotion_score_list[0]
|
||
if flag:
|
||
# if result['success']:
|
||
return jsonify({
|
||
"success": True,
|
||
"message": "人脸分析成功",
|
||
"data": {
|
||
"emotion_state": emotion_state,
|
||
"video_path": video_path,
|
||
"confidence": confidence
|
||
}
|
||
}), 201
|
||
else:
|
||
return jsonify({
|
||
"success": False,
|
||
"message": "添加失败",
|
||
"error": result.get('error', '未知错误')
|
||
}), 500
|
||
|
||
except Exception as e:
|
||
return jsonify({
|
||
"success": False,
|
||
"message": "服务器内部错误",
|
||
"error": str(e)
|
||
}), 500 |