Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1^2
zouap 3 years ago
parent
commit
450993bd46
2 changed files with 76 additions and 0 deletions
  1. +12
    -0
      routers/private/tool.go
  2. +64
    -0
      routers/repo/ai_model_manage.go

+ 12
- 0
routers/private/tool.go View File

@@ -44,3 +44,15 @@ func RepoStatisticManually(ctx *macaron.Context) {
repo.SummaryStatisticDaily(date)
repo.TimingCountDataByDate(date)
}

func CreateModel(ctx *macaron.Context) {
trainTaskId := ctx.QueryInt64("TrainTask")
name := ctx.Query("Name")
version := ctx.Query("Version")
label := ctx.Query("Label")
description := ctx.Query("Description")
userId := ctx.QueryInt64("userId")

repo.SaveModelByParameters(trainTaskId, name, version, label, description, userId)

}

+ 64
- 0
routers/repo/ai_model_manage.go View File

@@ -17,6 +17,70 @@ import (
uuid "github.com/satori/go.uuid"
)

func SaveModelByParameters(trainTaskId int64, name string, version string, label string, description string, userId int64) {
aiTasks, _, err := models.Cloudbrains(&models.CloudbrainsOptions{
JobID: trainTaskId,
})
if err != nil {
log.Info("query task error." + err.Error())
//ctx.Error(500, fmt.Sprintf("query cloud brain train task error. %v", err))
return
}
uuid := uuid.NewV4()
id := uuid.String()
modelPath := id
parent := id
var modelSize int64
cloudType := models.TypeCloudBrainTwo

if len(aiTasks) != 1 {
log.Info("query task error. len=" + fmt.Sprint(len(aiTasks)))
//ctx.Error(500, fmt.Sprintf("query cloud brain train task error. %v", err))
return
}
aiTask := aiTasks[0]
log.Info("find task name:" + aiTask.JobName)
aimodels := models.QueryModelByName(name, userId)
if len(aimodels) > 0 {
for _, model := range aimodels {
if model.ID == model.Parent {
parent = model.ID
}
}
}
cloudType = aiTask.Cloudbrain.Type
//download model zip //train type
if cloudType == models.TypeCloudBrainTrainJob {
modelPath, modelSize, err = downloadModelFromCloudBrainTwo(id, aiTask.JobName, "")
if err == nil {

} else {
log.Info("download model from CloudBrainTwo faild." + err.Error())
//ctx.Error(500, fmt.Sprintf("%v", err))
return
}
}

model := &models.AiModelManage{
ID: id,
Version: version,
Label: label,
Name: name,
Description: description,
Parent: parent,
Type: cloudType,
Path: modelPath,
Size: modelSize,
AttachmentId: aiTask.Uuid,
RepoId: aiTask.RepoID,
UserId: userId,
}

models.SaveModelToDb(model)

log.Info("save model end.")
}

func SaveModel(ctx *context.Context) {
log.Info("save model start.")
trainTaskId := ctx.QueryInt64("TrainTask")


Loading…
Cancel
Save