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

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