File size: 1,675 Bytes
37ddbc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""CLI dispatcher for `python3 -m data_label_factory.identify <command>`.

Subcommands:
    index    → build_index.main
    verify   → verify_index.main
    train    → train.main
    serve    → serve.main

Each is lazy-loaded so users only pay the import cost for the command they
actually invoke.
"""

from __future__ import annotations

import sys


HELP = """\
data_label_factory.identify — open-set image retrieval

usage: python3 -m data_label_factory.identify <command> [options]

commands:
  index    Build a CLIP retrieval index from a folder of reference images
  verify   Self-test an index and report margin / confusable pairs
  train    Contrastive fine-tune a projection head (improves accuracy)
  serve    Run an HTTP server that exposes the index as /api/falcon

run any command with --help for its options. The full blueprint is in
data_label_factory/identify/README.md.
"""


def main(argv: list[str] | None = None) -> int:
    args = list(argv) if argv is not None else sys.argv[1:]
    if not args or args[0] in ("-h", "--help", "help"):
        print(HELP)
        return 0

    cmd = args[0]
    rest = args[1:]

    if cmd == "index":
        from .build_index import main as _main
        return _main(rest)
    if cmd == "verify":
        from .verify_index import main as _main
        return _main(rest)
    if cmd == "train":
        from .train import main as _main
        return _main(rest)
    if cmd == "serve":
        from .serve import main as _main
        return _main(rest)

    print(f"unknown command: {cmd}\n", file=sys.stderr)
    print(HELP, file=sys.stderr)
    return 1


if __name__ == "__main__":
    sys.exit(main())