|
|
|
@@ -33,13 +33,13 @@ const ( |
|
|
|
STATUS_ERROR = 2 |
|
|
|
) |
|
|
|
|
|
|
|
func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, engine int, ctx *context.Context) error { |
|
|
|
func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, engine int, ctx *context.Context) (string, error) { |
|
|
|
aiTask, err := models.GetCloudbrainByJobIDAndVersionName(jobId, versionName) |
|
|
|
if err != nil { |
|
|
|
aiTask, err = models.GetRepoCloudBrainByJobID(ctx.Repo.Repository.ID, jobId) |
|
|
|
if err != nil { |
|
|
|
log.Info("query task error." + err.Error()) |
|
|
|
return err |
|
|
|
return "", err |
|
|
|
} else { |
|
|
|
log.Info("query gpu train task.") |
|
|
|
} |
|
|
|
@@ -55,7 +55,7 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
if len(aimodels) > 0 { |
|
|
|
for _, model := range aimodels { |
|
|
|
if model.Version == version { |
|
|
|
return errors.New(ctx.Tr("repo.model.manage.create_error")) |
|
|
|
return "", errors.New(ctx.Tr("repo.model.manage.create_error")) |
|
|
|
} |
|
|
|
if model.New == MODEL_LATEST { |
|
|
|
lastNewModelId = model.ID |
|
|
|
@@ -113,7 +113,7 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
|
|
|
|
err = models.SaveModelToDb(model) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return "", err |
|
|
|
} |
|
|
|
if len(lastNewModelId) > 0 { |
|
|
|
//udpate status and version count |
|
|
|
@@ -136,7 +136,7 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
|
|
|
|
log.Info("save model end.") |
|
|
|
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, id, name, models.ActionCreateNewModelTask) |
|
|
|
return nil |
|
|
|
return id, nil |
|
|
|
} |
|
|
|
|
|
|
|
func asyncToCopyModel(aiTask *models.Cloudbrain, id string, modelSelectedFile string) { |
|
|
|
@@ -206,29 +206,33 @@ func SaveModel(ctx *context.Context) { |
|
|
|
engine := ctx.QueryInt("engine") |
|
|
|
modelSelectedFile := ctx.Query("modelSelectedFile") |
|
|
|
log.Info("engine=" + fmt.Sprint(engine) + " modelSelectedFile=" + modelSelectedFile) |
|
|
|
|
|
|
|
re := map[string]string{ |
|
|
|
"code": "-1", |
|
|
|
} |
|
|
|
if JobId == "" || VersionName == "" { |
|
|
|
ctx.Error(500, fmt.Sprintf("JobId or VersionName is null.")) |
|
|
|
re["msg"] = "JobId or VersionName is null." |
|
|
|
ctx.JSON(200, re) |
|
|
|
return |
|
|
|
} |
|
|
|
if modelSelectedFile == "" { |
|
|
|
ctx.Error(500, fmt.Sprintf("Not selected model file.")) |
|
|
|
re["msg"] = "Not selected model file." |
|
|
|
ctx.JSON(200, re) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if name == "" || version == "" { |
|
|
|
ctx.Error(500, fmt.Sprintf("name or version is null.")) |
|
|
|
re["msg"] = "name or version is null." |
|
|
|
ctx.JSON(200, re) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err := saveModelByParameters(JobId, VersionName, name, version, label, description, engine, ctx) |
|
|
|
|
|
|
|
id, err := saveModelByParameters(JobId, VersionName, name, version, label, description, engine, ctx) |
|
|
|
if err != nil { |
|
|
|
log.Info("save model error." + err.Error()) |
|
|
|
ctx.Error(500, fmt.Sprintf("save model error. %v", err)) |
|
|
|
return |
|
|
|
re["msg"] = err.Error() |
|
|
|
} else { |
|
|
|
re["code"] = "0" |
|
|
|
re["id"] = id |
|
|
|
} |
|
|
|
ctx.Status(200) |
|
|
|
ctx.JSON(200, re) |
|
|
|
log.Info("save model end.") |
|
|
|
} |
|
|
|
|
|
|
|
@@ -632,6 +636,19 @@ func ShowModelInfo(ctx *context.Context) { |
|
|
|
ctx.HTML(200, tplModelInfo) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryModelById(ctx *context.Context) { |
|
|
|
id := ctx.Query("id") |
|
|
|
model, err := models.QueryModelById(id) |
|
|
|
if err == nil { |
|
|
|
model.IsCanOper = isOper(ctx, model.UserId) |
|
|
|
model.IsCanDelete = isCanDelete(ctx, model.UserId) |
|
|
|
removeIpInfo(model) |
|
|
|
ctx.JSON(http.StatusOK, model) |
|
|
|
} else { |
|
|
|
ctx.JSON(http.StatusNotFound, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func ShowSingleModel(ctx *context.Context) { |
|
|
|
name := ctx.Query("name") |
|
|
|
|
|
|
|
|