Skip to content

Cli

cli()

CLI for various AI agents.

Source code in mbodied/agents/cli.py
10
11
12
13
@click.group()
def cli():
    """CLI for various AI agents."""
    pass

detect(model_src, image_path, objects, model_type, api_name)

Run the ObjectDetectionAgent to detect objects in an image.

Source code in mbodied/agents/cli.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@cli.command()
@click.option("--model-src", default="https://api.mbodi.ai/sense/", help="The model source URL.")
@click.option("--image-path", prompt="Image path", help="Path to the image file.")
@click.option("--objects", prompt="Objects to detect", help="Comma-separated list of objects to detect.")
@click.option(
    "--model-type",
    type=click.Choice(["YOLOWorld", "Grounding DINO"], case_sensitive=False),
    prompt="Model type",
    help="The model type to use for detection.",
)
@click.option("--api-name", default="/detect", help="The API endpoint to use.")
def detect(model_src, image_path, objects, model_type, api_name):
    """Run the ObjectDetectionAgent to detect objects in an image."""
    image = Image(image_path, size=(224, 224))
    objects_list = objects.split(",")
    agent = ObjectDetectionAgent(model_src=model_src)
    result = agent.act(image=image, objects=objects_list, model_type=model_type, api_name=api_name)
    result.annotated.pil.show()

estimate_depth(model_src, image_path, api_name)

Run the DepthEstimationAgent to estimate depth from an image.

Source code in mbodied/agents/cli.py
36
37
38
39
40
41
42
43
44
45
@cli.command()
@click.option("--model-src", default="https://api.mbodi.ai/sense/", help="The model source URL.")
@click.option("--image-path", prompt="Image path", help="Path to the image file.")
@click.option("--api-name", default="/depth", help="The API endpoint to use.")
def estimate_depth(model_src, image_path, api_name):
    """Run the DepthEstimationAgent to estimate depth from an image."""
    image = Image(image_path, size=(224, 224))
    agent = DepthEstimationAgent(model_src=model_src)
    result = agent.act(image=image, api_name=api_name)
    result.pil.show()

segment(model_src, image_path, input_type, input_data, api_name)

Run the SegmentationAgent to segment objects in an image.

Source code in mbodied/agents/cli.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@cli.command()
@click.option("--model-src", default="https://api.mbodi.ai/sense/", help="The model source URL.")
@click.option("--image-path", prompt="Image path", help="Path to the image file.")
@click.option(
    "--input-type",
    type=click.Choice(["bbox", "coords"], case_sensitive=False),
    prompt="Input type",
    help="Type of input data (bbox or coords).",
)
@click.option(
    "--input-data", prompt="Input data", help="Bounding box coordinates as x1,y1,x2,y2 or pixel coordinates as u,v."
)
@click.option("--api-name", default="/segment", help="The API endpoint to use.")
def segment(model_src, image_path, input_type, input_data, api_name):
    """Run the SegmentationAgent to segment objects in an image."""
    image = Image(image_path, size=(224, 224))
    agent = SegmentationAgent(model_src=model_src)

    if input_type == "bbox":
        bbox_coords = list(map(int, input_data.split(",")))
        input_data = BBox2D(x1=bbox_coords[0], y1=bbox_coords[1], x2=bbox_coords[2], y2=bbox_coords[3])
    elif input_type == "coords":
        u, v = map(int, input_data.split(","))
        input_data = PixelCoords(u=u, v=v)

    mask_image, masks = agent.act(image=image, input_data=input_data, api_name=api_name)
    print("Masks shape:", masks.shape)
    mask_image.pil.show()