diff --git a/core/http/routes/ui_api.go b/core/http/routes/ui_api.go index 31dd66e1f..208f8dc45 100644 --- a/core/http/routes/ui_api.go +++ b/core/http/routes/ui_api.go @@ -1,5 +1,7 @@ package routes +import "os" + import ( "context" "fmt" @@ -32,6 +34,25 @@ const ( ascSortOrder = "asc" ) +// getDirectorySize calculates the total size of files in a directory +func getDirectorySize(path string) (int64, error) { + var totalSize int64 + entries, err := os.ReadDir(path) + if err != nil { + return 0, err + } + for _, entry := range entries { + info, err := entry.Info() + if err != nil { + continue + } + if !info.IsDir() { + totalSize += info.Size() + } + } + return totalSize, nil +} + // RegisterUIAPIRoutes registers JSON API routes for the web UI func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig, galleryService *services.GalleryService, opcache *services.OpCache, applicationInstance *application.Application) { @@ -297,6 +318,12 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY) installedModelsCount := len(modelConfigs) + len(modelsWithoutConfig) + // Calculate storage size and RAM info + modelsPath := appConfig.SystemState.Model.ModelsPath + storageSize, _ := getDirectorySize(modelsPath) + + ramInfo, _ := xsysinfo.GetSystemRAMInfo() + return c.JSON(200, map[string]interface{}{ "models": modelsJSON, "repositories": appConfig.Galleries, @@ -305,6 +332,10 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model "taskTypes": taskTypes, "availableModels": totalModels, "installedModels": installedModelsCount, + "storageSize": storageSize, + "ramTotal": ramInfo.Total, + "ramUsed": ramInfo.Used, + "ramUsagePercent": ramInfo.UsagePercent, "currentPage": pageNum, "totalPages": totalPages, "prevPage": prevPage, diff --git a/core/http/views/models.html b/core/http/views/models.html index 7684a9e78..8e4541910 100644 --- a/core/http/views/models.html +++ b/core/http/views/models.html @@ -61,6 +61,15 @@ repositories +
+
+ + storage +
+
+ + Storage exceeds RAM! +
Import Model @@ -605,6 +614,10 @@ function modelsGallery() { totalPages: 1, availableModels: 0, installedModels: 0, + storageSize: 0, + ramTotal: 0, + ramUsed: 0, + ramUsagePercent: 0, selectedModel: null, jobProgress: {}, notifications: [], @@ -650,6 +663,10 @@ function modelsGallery() { this.totalPages = data.totalPages || 1; this.availableModels = data.availableModels || 0; this.installedModels = data.installedModels || 0; + this.storageSize = data.storageSize || 0; + this.ramTotal = data.ramTotal || 0; + this.ramUsed = data.ramUsed || 0; + this.ramUsagePercent = data.ramUsagePercent || 0; } catch (error) { console.error('Error fetching models:', error); } finally { @@ -826,6 +843,14 @@ function modelsGallery() { this.selectedModel = model; }, + formatBytes(bytes) { + if (bytes === 0) return "0 B"; + const k = 1024; + const sizes = ["B", "KB", "MB", "GB", "TB"]; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i]; + }, + closeModal() { this.selectedModel = null; }