|
|
|
@@ -28,7 +28,6 @@ const ( |
|
|
|
|
|
|
|
func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, ctx *context.Context) error { |
|
|
|
aiTask, err := models.GetCloudbrainByJobIDAndVersionName(jobId, versionName) |
|
|
|
//aiTask, err := models.GetCloudbrainByJobID(jobId) |
|
|
|
if err != nil { |
|
|
|
log.Info("query task error." + err.Error()) |
|
|
|
return err |
|
|
|
@@ -56,7 +55,7 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
cloudType = aiTask.Type |
|
|
|
//download model zip //train type |
|
|
|
if cloudType == models.TypeCloudBrainTwo { |
|
|
|
modelPath, modelSize, err = downloadModelFromCloudBrainTwo(id, aiTask.JobName, "") |
|
|
|
modelPath, modelSize, err = downloadModelFromCloudBrainTwo(id, aiTask.JobName, "", aiTask.TrainUrl) |
|
|
|
if err != nil { |
|
|
|
log.Info("download model from CloudBrainTwo faild." + err.Error()) |
|
|
|
return err |
|
|
|
@@ -71,7 +70,6 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
log.Info("accuracyJson=" + string(accuracyJson)) |
|
|
|
aiTaskJson, _ := json.Marshal(aiTask) |
|
|
|
|
|
|
|
//taskConfigInfo,err := models.GetCloudbrainByJobIDAndVersionName(jobId,aiTask.VersionName) |
|
|
|
model := &models.AiModelManage{ |
|
|
|
ID: id, |
|
|
|
Version: version, |
|
|
|
@@ -86,7 +84,6 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
AttachmentId: aiTask.Uuid, |
|
|
|
RepoId: aiTask.RepoID, |
|
|
|
UserId: ctx.User.ID, |
|
|
|
UserName: ctx.User.Name, |
|
|
|
UserRelAvatarLink: ctx.User.RelAvatarLink(), |
|
|
|
CodeBranch: aiTask.BranchName, |
|
|
|
CodeCommitID: aiTask.CommitID, |
|
|
|
@@ -144,9 +141,12 @@ func SaveModel(ctx *context.Context) { |
|
|
|
log.Info("save model end.") |
|
|
|
} |
|
|
|
|
|
|
|
func downloadModelFromCloudBrainTwo(modelUUID string, jobName string, parentDir string) (string, int64, error) { |
|
|
|
|
|
|
|
func downloadModelFromCloudBrainTwo(modelUUID string, jobName string, parentDir string, trainUrl string) (string, int64, error) { |
|
|
|
objectkey := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, setting.OutPutPath, parentDir), "/") |
|
|
|
if trainUrl != "" { |
|
|
|
objectkey = strings.Trim(trainUrl[len(setting.Bucket)+1:], "/") |
|
|
|
} |
|
|
|
|
|
|
|
modelDbResult, err := storage.GetOneLevelAllObjectUnderDir(setting.Bucket, objectkey, "") |
|
|
|
log.Info("bucket=" + setting.Bucket + " objectkey=" + objectkey) |
|
|
|
if err != nil { |
|
|
|
@@ -395,15 +395,42 @@ func ShowSingleModel(ctx *context.Context) { |
|
|
|
ctx.JSON(http.StatusOK, models) |
|
|
|
} |
|
|
|
|
|
|
|
func queryUserName(intSlice []int64) map[int64]string { |
|
|
|
keys := make(map[int64]string) |
|
|
|
uniqueElements := []int64{} |
|
|
|
for _, entry := range intSlice { |
|
|
|
if _, value := keys[entry]; !value { |
|
|
|
keys[entry] = "" |
|
|
|
uniqueElements = append(uniqueElements, entry) |
|
|
|
} |
|
|
|
} |
|
|
|
userNames, err := models.GetUserNamesByIDs(uniqueElements) |
|
|
|
if err == nil { |
|
|
|
for i, userName := range userNames { |
|
|
|
keys[uniqueElements[i]] = userName |
|
|
|
} |
|
|
|
} |
|
|
|
return keys |
|
|
|
} |
|
|
|
|
|
|
|
func ShowOneVersionOtherModel(ctx *context.Context) { |
|
|
|
repoId := ctx.Repo.Repository.ID |
|
|
|
name := ctx.Query("name") |
|
|
|
aimodels := models.QueryModelByName(name, repoId) |
|
|
|
for _, model := range aimodels { |
|
|
|
|
|
|
|
userIds := make([]int64, len(aimodels)) |
|
|
|
for i, model := range aimodels { |
|
|
|
log.Info("model=" + model.Name) |
|
|
|
log.Info("model.UserId=" + fmt.Sprint(model.UserId)) |
|
|
|
model.IsCanOper = isOper(ctx, model.UserId) |
|
|
|
userIds[i] = model.UserId |
|
|
|
} |
|
|
|
userNameMap := queryUserName(userIds) |
|
|
|
|
|
|
|
for _, model := range aimodels { |
|
|
|
model.UserName = userNameMap[model.UserId] |
|
|
|
} |
|
|
|
|
|
|
|
if len(aimodels) > 0 { |
|
|
|
ctx.JSON(200, aimodels[1:]) |
|
|
|
} else { |
|
|
|
@@ -431,7 +458,7 @@ func isOper(ctx *context.Context, modelUserId int64) bool { |
|
|
|
if ctx.User == nil { |
|
|
|
return false |
|
|
|
} |
|
|
|
if ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() || ctx.User.ID == modelUserId { |
|
|
|
if ctx.User.IsAdmin || ctx.Repo.IsOwner() || ctx.User.ID == modelUserId { |
|
|
|
return true |
|
|
|
} |
|
|
|
return false |
|
|
|
@@ -463,10 +490,17 @@ func ShowModelPageInfo(ctx *context.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
for _, model := range modelResult { |
|
|
|
userIds := make([]int64, len(modelResult)) |
|
|
|
for i, model := range modelResult { |
|
|
|
log.Info("model=" + model.Name) |
|
|
|
log.Info("model.UserId=" + fmt.Sprint(model.UserId)) |
|
|
|
model.IsCanOper = isOper(ctx, model.UserId) |
|
|
|
userIds[i] = model.UserId |
|
|
|
} |
|
|
|
|
|
|
|
userNameMap := queryUserName(userIds) |
|
|
|
for _, model := range modelResult { |
|
|
|
model.UserName = userNameMap[model.UserId] |
|
|
|
} |
|
|
|
|
|
|
|
mapInterface := make(map[string]interface{}) |
|
|
|
|