You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

modelmanage.go 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package repo
  2. import (
  3. "net/http"
  4. "code.gitea.io/gitea/modules/context"
  5. "code.gitea.io/gitea/modules/convert"
  6. "code.gitea.io/gitea/modules/log"
  7. "code.gitea.io/gitea/modules/storage"
  8. api "code.gitea.io/gitea/modules/structs"
  9. routerRepo "code.gitea.io/gitea/routers/repo"
  10. )
  11. type FileInfo struct {
  12. FileName string `json:"fileName"`
  13. ModTime string `json:"modTime"`
  14. IsDir bool `json:"isDir"`
  15. Size int64 `json:"size"`
  16. ParenDir string `json:"parenDir"`
  17. UUID string `json:"uuid"`
  18. }
  19. func CreateNewModel(ctx *context.APIContext) {
  20. log.Info("CreateNewModel by api.")
  21. routerRepo.SaveModel(ctx.Context)
  22. }
  23. func ShowModelManageApi(ctx *context.APIContext) {
  24. log.Info("ShowModelManageApi by api.")
  25. routerRepo.ShowModelPageInfo(ctx.Context)
  26. }
  27. func DeleteModel(ctx *context.APIContext) {
  28. log.Info("DeleteModel by api.")
  29. routerRepo.DeleteModel(ctx.Context)
  30. }
  31. func DownloadModel(ctx *context.APIContext) {
  32. log.Info("DownloadModel by api.")
  33. routerRepo.DownloadMultiModelFile(ctx.Context)
  34. }
  35. func QueryModelById(ctx *context.APIContext) {
  36. log.Info("QueryModelById by api.")
  37. routerRepo.QueryModelById(ctx.Context)
  38. }
  39. func QueryModelByName(ctx *context.APIContext) {
  40. log.Info("QueryModelByName by api.")
  41. routerRepo.ShowSingleModel(ctx.Context)
  42. }
  43. func QueryModelListForPredict(ctx *context.APIContext) {
  44. log.Info("QueryModelListForPredict by api.")
  45. ctx.Context.SetParams("isOnlyThisRepo", "true")
  46. routerRepo.QueryModelListForPredict(ctx.Context)
  47. }
  48. func QueryTrainJobList(ctx *context.APIContext) {
  49. result, err := routerRepo.QueryTrainJobListApi(ctx.Context)
  50. if err != nil {
  51. log.Info("query error." + err.Error())
  52. ctx.JSON(http.StatusOK, nil)
  53. } else {
  54. re := make([]*api.Cloudbrain, 0)
  55. for _, task := range result {
  56. conRe := convert.ToCloudBrain(task)
  57. re = append(re, conRe)
  58. }
  59. ctx.JSON(http.StatusOK, re)
  60. }
  61. }
  62. func QueryTrainModelList(ctx *context.APIContext) {
  63. result, err := routerRepo.QueryTrainModelFileById(ctx.Context)
  64. if err != nil {
  65. log.Info("query error." + err.Error())
  66. }
  67. re := convertFileFormat(result)
  68. ctx.JSON(http.StatusOK, re)
  69. }
  70. func QueryTrainJobVersionList(ctx *context.APIContext) {
  71. result, err := routerRepo.QueryTrainJobVersionListApi(ctx.Context)
  72. if err != nil {
  73. log.Info("query error." + err.Error())
  74. ctx.JSON(http.StatusOK, nil)
  75. } else {
  76. re := make([]*api.Cloudbrain, 0)
  77. for _, task := range result {
  78. conRe := convert.ToCloudBrain(task)
  79. re = append(re, conRe)
  80. }
  81. ctx.JSON(http.StatusOK, re)
  82. }
  83. }
  84. func convertFileFormat(result []storage.FileInfo) []FileInfo {
  85. re := make([]FileInfo, 0)
  86. if result != nil {
  87. for _, file := range result {
  88. tmpFile := FileInfo{
  89. FileName: file.FileName,
  90. ModTime: file.ModTime,
  91. IsDir: file.IsDir,
  92. Size: file.Size,
  93. ParenDir: file.ParenDir,
  94. UUID: file.UUID,
  95. }
  96. re = append(re, tmpFile)
  97. }
  98. }
  99. return re
  100. }
  101. func QueryModelFileForPredict(ctx *context.APIContext) {
  102. log.Info("QueryModelFileForPredict by api.")
  103. id := ctx.Query("id")
  104. result := routerRepo.QueryModelFileByID(id)
  105. re := convertFileFormat(result)
  106. ctx.JSON(http.StatusOK, re)
  107. }
  108. func CreateModelConvert(ctx *context.APIContext) {
  109. log.Info("CreateModelConvert by api.")
  110. routerRepo.SaveModelConvert(ctx.Context)
  111. }
  112. func StopModelConvert(ctx *context.APIContext) {
  113. log.Info("StopModelConvert by api.")
  114. routerRepo.StopModelConvertApi(ctx.Context)
  115. }
  116. func ShowModelConvertPage(ctx *context.APIContext) {
  117. log.Info("ShowModelConvertPage by api.")
  118. modelResult, count, err := routerRepo.GetModelConvertPageData(ctx.Context)
  119. if err == nil {
  120. mapInterface := make(map[string]interface{})
  121. mapInterface["data"] = modelResult
  122. mapInterface["count"] = count
  123. ctx.JSON(http.StatusOK, mapInterface)
  124. } else {
  125. mapInterface := make(map[string]interface{})
  126. mapInterface["data"] = nil
  127. mapInterface["count"] = 0
  128. ctx.JSON(http.StatusOK, mapInterface)
  129. }
  130. }
  131. func QueryModelConvertById(ctx *context.APIContext) {
  132. modelResult, err := routerRepo.GetModelConvertById(ctx.Context)
  133. if err == nil {
  134. ctx.JSON(http.StatusOK, modelResult)
  135. } else {
  136. ctx.JSON(http.StatusOK, nil)
  137. }
  138. }
  139. func QueryModelConvertByName(ctx *context.APIContext) {
  140. modelResult, err := routerRepo.GetModelConvertByName(ctx.Context)
  141. if err == nil {
  142. ctx.JSON(http.StatusOK, modelResult)
  143. } else {
  144. ctx.JSON(http.StatusOK, nil)
  145. }
  146. }