65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
BACKEND_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(BACKEND_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(BACKEND_ROOT))
|
|
|
|
from app.core.config import Settings # noqa: E402
|
|
from app.services.yolo_preflight_service import YoloPreflightService # noqa: E402
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Run local YOLO configuration preflight without running inference.")
|
|
parser.add_argument("--model-path", help="Existing local YOLO model path.")
|
|
parser.add_argument("--tile-manifest-path", help="Existing raster tile manifest path.")
|
|
parser.add_argument("--enabled", action="store_true", help="Treat YOLO as enabled for this preflight.")
|
|
parser.add_argument("--max-tiles", type=int, help="Maximum tile count allowed by preflight.")
|
|
parser.add_argument(
|
|
"--assume-dependencies",
|
|
action="store_true",
|
|
help="Skip checking installed ultralytics/torch packages; useful for validating local paths on non-AI machines.",
|
|
)
|
|
parser.add_argument(
|
|
"--check-model-load",
|
|
action="store_true",
|
|
help="Explicitly load the configured local model file to verify Ultralytics compatibility; no inference is run.",
|
|
)
|
|
parser.add_argument("--json", action="store_true", help="Print JSON output only.")
|
|
args = parser.parse_args()
|
|
if args.check_model_load and args.assume_dependencies:
|
|
parser.error("--check-model-load cannot be combined with --assume-dependencies")
|
|
|
|
settings = Settings()
|
|
settings_updates = {}
|
|
if args.enabled or args.model_path:
|
|
settings_updates["yolo_enabled"] = True
|
|
if args.model_path:
|
|
settings_updates["yolo_model_path"] = args.model_path
|
|
if args.max_tiles is not None:
|
|
settings_updates["yolo_max_tiles"] = args.max_tiles
|
|
if settings_updates:
|
|
settings = settings.model_copy(update=settings_updates)
|
|
payload = YoloPreflightService.run(
|
|
settings=settings,
|
|
tile_manifest_path=args.tile_manifest_path,
|
|
assume_dependencies=args.assume_dependencies,
|
|
check_model_load=args.check_model_load,
|
|
)
|
|
|
|
if args.json:
|
|
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
else:
|
|
print("GeoIntel YOLO preflight")
|
|
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
return 0 if payload["status"] in {"ready", "not_configured", "dependency_unavailable"} else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|