模型开始训练界面以及查看日志功能完善
This commit is contained in:
@@ -193,3 +193,65 @@ def get_local_models():
|
||||
except Exception as e:
|
||||
logger.error(f"获取本地模型列表失败: {e}")
|
||||
return jsonify({'code': 1, 'message': str(e)})
|
||||
|
||||
|
||||
# ============ 已训练模型列表接口 ============
|
||||
|
||||
@model_manage_bp.route('/trained-models', methods=['GET'])
|
||||
def get_trained_models():
|
||||
"""获取已训练模型列表(从/app/base/saves目录)"""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
# 使用 /app/base/saves 目录(容器内路径)
|
||||
saves_base_path = '/app/base/saves'
|
||||
# 本地开发时的备用路径
|
||||
local_saves_path = os.path.join(PROJECT_ROOT, 'saves')
|
||||
|
||||
# 选择存在的路径
|
||||
base_path = saves_base_path if os.path.exists(saves_base_path) else local_saves_path
|
||||
|
||||
logger.info(f"[DEBUG] 已训练模型目录: {base_path}, exists: {os.path.exists(base_path)}")
|
||||
|
||||
models = []
|
||||
if os.path.exists(base_path):
|
||||
for item in os.listdir(base_path):
|
||||
item_path = os.path.join(base_path, item)
|
||||
if os.path.isdir(item_path):
|
||||
# 检查是否是模板目录(包含训练方法的子目录)
|
||||
sub_items = []
|
||||
if os.path.exists(item_path):
|
||||
for sub_item in os.listdir(item_path):
|
||||
sub_path = os.path.join(item_path, sub_item)
|
||||
if os.path.isdir(sub_path):
|
||||
# 检查是否包含模型文件(adapter_model.bin 或 pytorch_model.bin 等)
|
||||
has_model = False
|
||||
for f in os.listdir(sub_path):
|
||||
if f.endswith('.bin') or f.endswith('.safetensors'):
|
||||
has_model = True
|
||||
break
|
||||
if has_model:
|
||||
sub_items.append({
|
||||
'name': sub_item,
|
||||
'path': sub_path
|
||||
})
|
||||
|
||||
models.append({
|
||||
'name': item,
|
||||
'path': item_path,
|
||||
'train_methods': sub_items
|
||||
})
|
||||
|
||||
logger.info(f"[DEBUG] 找到 {len(models)} 个已训练模型")
|
||||
|
||||
return jsonify({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'models': models,
|
||||
'base_path': base_path
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"获取已训练模型列表失败: {e}")
|
||||
return jsonify({'code': 1, 'message': str(e)})
|
||||
|
||||
Reference in New Issue
Block a user