cmvr_edge_ai/client/detect/example.py

41 lines
1.1 KiB
Python
Raw Permalink Normal View History

"""Call a Detect Server without constructing an edge-AI pipeline."""
from __future__ import annotations
import asyncio
import os
import sys
from pathlib import Path
from cmvr_edge_ai.client.detect import DetectClient
async def main() -> None:
if len(sys.argv) != 3:
raise SystemExit("usage: example.py IMAGE_PATH CATEGORY")
image_path = Path(sys.argv[1])
category = sys.argv[2]
base_url = os.environ.get("CMVR_DETECT_BASE_URL", "http://127.0.0.1:8081")
bearer_token = os.environ.get("CMVR_DETECT_BEARER_TOKEN")
headers = (
{}
if bearer_token is None
else {"Authorization": f"Bearer {bearer_token}"}
)
async with DetectClient(base_url, headers=headers) as client:
models = await client.list_models()
print(models)
result = await client.infer(
category,
image_path.read_bytes(),
media_type="image/jpeg",
parameters={},
image_roles=("annotated", "original"),
)
print(result)
if __name__ == "__main__":
asyncio.run(main())