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 3.5 kB

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