Files
photoprism/internal/commands/vision_list.go
2025-09-02 11:01:52 +02:00

79 lines
1.8 KiB
Go

package commands
import (
"encoding/json"
"fmt"
"strings"
"github.com/dustin/go-humanize/english"
"github.com/urfave/cli/v2"
"github.com/photoprism/photoprism/internal/ai/vision"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/pkg/txt/report"
)
// VisionListCommand configures the command name, flags, and action.
var VisionListCommand = &cli.Command{
Name: "ls",
Usage: "Lists the configured computer vision models",
Flags: append(report.CliFlags),
Action: visionListAction,
}
// visionListAction displays existing user accounts.
func visionListAction(ctx *cli.Context) error {
return CallWithDependencies(ctx, func(conf *config.Config) error {
var rows [][]string
cols := []string{"Type", "Name", "Version", "Resolution", "Service Endpoint", "Options", "Tags", "Disabled"}
// Show log message.
log.Infof("found %s", english.Plural(len(vision.Config.Models), "model", "models"))
if n := len(vision.Config.Models); n == 0 {
return nil
} else {
rows = make([][]string, n)
}
// Display report.
for i, model := range vision.Config.Models {
modelUri, modelMethod := model.Endpoint()
tags := ""
_, name, version := model.Model()
if model.TensorFlow != nil && model.TensorFlow.Tags != nil {
tags = strings.Join(model.TensorFlow.Tags, ", ")
}
if model.Default {
version = "default"
}
var options []byte
if o := model.GetOptions(); o != nil {
options, _ = json.Marshal(*o)
}
rows[i] = []string{
model.Type,
name,
version,
fmt.Sprintf("%d", model.Resolution),
fmt.Sprintf("%s %s", modelMethod, modelUri),
string(options),
tags,
report.Bool(model.Disabled, report.Yes, report.No),
}
}
result, err := report.RenderFormat(rows, cols, report.CliFormat(ctx))
fmt.Printf("\n%s\n", result)
return err
})
}