Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.11.2^2
zouap 3 years ago
parent
commit
187eec79b2
3 changed files with 39 additions and 16 deletions
  1. +1
    -0
      routers/api/v1/api.go
  2. +5
    -0
      routers/api/v1/repo/modelmanage.go
  3. +33
    -16
      routers/repo/ai_model_manage.go

+ 1
- 0
routers/api/v1/api.go View File

@@ -990,6 +990,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/show_model_api", repo.ShowModelManageApi)
m.Delete("/delete_model", repo.DeleteModel)
m.Get("/downloadall", repo.DownloadModel)
m.Get("/query_model_byId", repo.QueryModelById)
m.Get("/query_model_for_predict", repo.QueryModelListForPredict)
m.Get("/query_modelfile_for_predict", repo.QueryModelFileForPredict)
m.Post("/create_model_convert", repo.CreateModelConvert)


+ 5
- 0
routers/api/v1/repo/modelmanage.go View File

@@ -37,6 +37,11 @@ func DownloadModel(ctx *context.APIContext) {
routerRepo.DownloadMultiModelFile(ctx.Context)
}

func QueryModelById(ctx *context.APIContext) {
log.Info("QueryModelById by api.")
routerRepo.QueryModelById(ctx.Context)
}

func QueryModelListForPredict(ctx *context.APIContext) {
log.Info("QueryModelListForPredict by api.")
routerRepo.QueryModelListForPredict(ctx.Context)


+ 33
- 16
routers/repo/ai_model_manage.go View File

@@ -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")



Loading…
Cancel
Save