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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 QueryModelListForPredict(ctx *context.APIContext) {
  38. log.Info("QueryModelListForPredict by api.")
  39. ctx.Context.SetParams("isOnlyThisRepo", "true")
  40. routerRepo.QueryModelListForPredict(ctx.Context)
  41. }
  42. func QueryTrainModelList(ctx *context.APIContext) {
  43. result, err := routerRepo.QueryTrainModelFileById(ctx.Context)
  44. if err != nil {
  45. log.Info("query error." + err.Error())
  46. }
  47. re := convertFileFormat(result)
  48. ctx.JSON(http.StatusOK, re)
  49. }
  50. func convertFileFormat(result []storage.FileInfo) []FileInfo {
  51. re := make([]FileInfo, 0)
  52. if result != nil {
  53. for _, file := range result {
  54. tmpFile := FileInfo{
  55. FileName: file.FileName,
  56. ModTime: file.ModTime,
  57. IsDir: file.IsDir,
  58. Size: file.Size,
  59. ParenDir: file.ParenDir,
  60. UUID: file.UUID,
  61. }
  62. re = append(re, tmpFile)
  63. }
  64. }
  65. return re
  66. }
  67. func QueryModelFileForPredict(ctx *context.APIContext) {
  68. log.Info("QueryModelFileForPredict by api.")
  69. id := ctx.Query("id")
  70. result := routerRepo.QueryModelFileByID(id)
  71. re := convertFileFormat(result)
  72. ctx.JSON(http.StatusOK, re)
  73. }
  74. func CreateModelConvert(ctx *context.APIContext) {
  75. log.Info("CreateModelConvert by api.")
  76. routerRepo.SaveModelConvert(ctx.Context)
  77. }
  78. func StopModelConvert(ctx *context.APIContext) {
  79. log.Info("StopModelConvert by api.")
  80. routerRepo.StopModelConvertApi(ctx.Context)
  81. }
  82. func ShowModelConvertPage(ctx *context.APIContext) {
  83. log.Info("ShowModelConvertPage by api.")
  84. modelResult, count, err := routerRepo.GetModelConvertPageData(ctx.Context)
  85. if err == nil {
  86. mapInterface := make(map[string]interface{})
  87. mapInterface["data"] = modelResult
  88. mapInterface["count"] = count
  89. ctx.JSON(http.StatusOK, mapInterface)
  90. } else {
  91. mapInterface := make(map[string]interface{})
  92. mapInterface["data"] = nil
  93. mapInterface["count"] = 0
  94. ctx.JSON(http.StatusOK, mapInterface)
  95. }
  96. }
  97. func QueryModelConvertById(ctx *context.APIContext) {
  98. modelResult, err := routerRepo.GetModelConvertById(ctx.Context)
  99. if err == nil {
  100. ctx.JSON(http.StatusOK, modelResult)
  101. } else {
  102. ctx.JSON(http.StatusOK, nil)
  103. }
  104. }