|
|
|
|
@ -679,3 +679,114 @@ def get_evaluate_task(task_id, current_user_id):
|
|
|
|
|
if not task:
|
|
|
|
|
return TaskService.json_error('任务不存在或无权限', 404)
|
|
|
|
|
return jsonify({'task': TaskService.serialize_task(task)}), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ==================== 3D可视化坐标接口 ====================
|
|
|
|
|
|
|
|
|
|
@task_bp.route('/finetune/<int:task_id>/coords', methods=['GET'])
|
|
|
|
|
@int_jwt_required
|
|
|
|
|
def get_finetune_coords(task_id, current_user_id):
|
|
|
|
|
"""
|
|
|
|
|
获取微调任务的3D可视化坐标CSV文件
|
|
|
|
|
|
|
|
|
|
返回格式:
|
|
|
|
|
- 基于加噪任务的微调:返回 original_coords.csv 和 perturbed_coords.csv
|
|
|
|
|
- 上传图片的微调:返回 coords.csv
|
|
|
|
|
"""
|
|
|
|
|
import os
|
|
|
|
|
import csv
|
|
|
|
|
from config.settings import Config
|
|
|
|
|
|
|
|
|
|
# 验证任务存在且属于当前用户
|
|
|
|
|
task = TaskService.load_task_for_user(task_id, current_user_id, expected_type='finetune')
|
|
|
|
|
if not task:
|
|
|
|
|
return TaskService.json_error('任务不存在或无权限', 404)
|
|
|
|
|
|
|
|
|
|
# 获取任务详情
|
|
|
|
|
finetune = Finetune.query.get(task_id)
|
|
|
|
|
if not finetune:
|
|
|
|
|
return TaskService.json_error('微调任务详情不存在', 404)
|
|
|
|
|
|
|
|
|
|
# 判断微调类型
|
|
|
|
|
try:
|
|
|
|
|
source = TaskService.determine_finetune_source(task)
|
|
|
|
|
except ValueError as exc:
|
|
|
|
|
return TaskService.json_error(str(exc), 500)
|
|
|
|
|
|
|
|
|
|
# 构建CSV文件路径
|
|
|
|
|
coords_base_path = TaskService._build_path(
|
|
|
|
|
Config.COORDS_SAVE_FOLDER,
|
|
|
|
|
str(current_user_id),
|
|
|
|
|
str(task.flow_id),
|
|
|
|
|
str(task_id)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = {
|
|
|
|
|
'task_id': task_id,
|
|
|
|
|
'flow_id': task.flow_id,
|
|
|
|
|
'source': source,
|
|
|
|
|
'coords': []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if source == 'perturbation':
|
|
|
|
|
# 基于加噪任务的微调,返回两个CSV文件
|
|
|
|
|
original_csv_path = os.path.join(coords_base_path, 'original_coords.csv')
|
|
|
|
|
perturbed_csv_path = os.path.join(coords_base_path, 'perturbed_coords.csv')
|
|
|
|
|
|
|
|
|
|
# 读取 original_coords.csv
|
|
|
|
|
if os.path.exists(original_csv_path):
|
|
|
|
|
try:
|
|
|
|
|
with open(original_csv_path, 'r', encoding='utf-8') as f:
|
|
|
|
|
reader = csv.DictReader(f)
|
|
|
|
|
original_data = [row for row in reader]
|
|
|
|
|
result['coords'].append({
|
|
|
|
|
'type': 'original',
|
|
|
|
|
'filename': 'original_coords.csv',
|
|
|
|
|
'path': original_csv_path,
|
|
|
|
|
'data': original_data
|
|
|
|
|
})
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return TaskService.json_error(f'读取原图坐标文件失败: {str(e)}', 500)
|
|
|
|
|
else:
|
|
|
|
|
return TaskService.json_error('原图坐标文件不存在', 404)
|
|
|
|
|
|
|
|
|
|
# 读取 perturbed_coords.csv
|
|
|
|
|
if os.path.exists(perturbed_csv_path):
|
|
|
|
|
try:
|
|
|
|
|
with open(perturbed_csv_path, 'r', encoding='utf-8') as f:
|
|
|
|
|
reader = csv.DictReader(f)
|
|
|
|
|
perturbed_data = [row for row in reader]
|
|
|
|
|
result['coords'].append({
|
|
|
|
|
'type': 'perturbed',
|
|
|
|
|
'filename': 'perturbed_coords.csv',
|
|
|
|
|
'path': perturbed_csv_path,
|
|
|
|
|
'data': perturbed_data
|
|
|
|
|
})
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return TaskService.json_error(f'读取加噪图坐标文件失败: {str(e)}', 500)
|
|
|
|
|
else:
|
|
|
|
|
return TaskService.json_error('加噪图坐标文件不存在', 404)
|
|
|
|
|
|
|
|
|
|
else: # source == 'uploaded'
|
|
|
|
|
# 上传图片的微调,返回一个CSV文件
|
|
|
|
|
coords_csv_path = os.path.join(coords_base_path, 'coords.csv')
|
|
|
|
|
|
|
|
|
|
if os.path.exists(coords_csv_path):
|
|
|
|
|
try:
|
|
|
|
|
with open(coords_csv_path, 'r', encoding='utf-8') as f:
|
|
|
|
|
reader = csv.DictReader(f)
|
|
|
|
|
coords_data = [row for row in reader]
|
|
|
|
|
result['coords'].append({
|
|
|
|
|
'type': 'uploaded',
|
|
|
|
|
'filename': 'coords.csv',
|
|
|
|
|
'path': coords_csv_path,
|
|
|
|
|
'data': coords_data
|
|
|
|
|
})
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return TaskService.json_error(f'读取坐标文件失败: {str(e)}', 500)
|
|
|
|
|
else:
|
|
|
|
|
return TaskService.json_error('坐标文件不存在', 404)
|
|
|
|
|
|
|
|
|
|
return jsonify(result), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|