nexaai 1.0.22rc1__cp310-cp310-macosx_13_0_x86_64.whl → 1.0.23__cp310-cp310-macosx_13_0_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nexaai might be problematic. Click here for more details.

Binary file
nexaai/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is generated by CMake from _version.py.in
2
2
  # Do not modify this file manually - it will be overwritten
3
3
 
4
- __version__ = "1.0.22-rc1"
4
+ __version__ = "1.0.23"
Binary file
nexaai/cv.py CHANGED
@@ -10,7 +10,7 @@ from nexaai.common import PluginID
10
10
  class BoundingBox:
11
11
  """Generic bounding box structure."""
12
12
  x: float # X coordinate (normalized or pixel, depends on model)
13
- y: float # Y coordinate (normalized or pixel, depends on model)
13
+ y: float # Y coordinate (normalized or pixel, depends on model)
14
14
  width: float # Width
15
15
  height: float # Height
16
16
 
@@ -24,7 +24,8 @@ class CVResult:
24
24
  confidence: float = 0.0 # Confidence score [0.0-1.0]
25
25
  bbox: Optional[BoundingBox] = None # Bounding box (example: YOLO)
26
26
  text: Optional[str] = None # Text result (example: OCR)
27
- embedding: Optional[List[float]] = None # Feature embedding (example: CLIP embedding)
27
+ # Feature embedding (example: CLIP embedding)
28
+ embedding: Optional[List[float]] = None
28
29
  embedding_dim: int = 0 # Embedding dimension
29
30
 
30
31
 
@@ -70,22 +71,23 @@ class CVModel(BaseModel):
70
71
 
71
72
  @classmethod
72
73
  def _load_from(cls,
73
- _: str, # TODO: remove this argument, this is a hack to make api design happy
74
- config: CVModelConfig,
74
+ local_path: str,
75
+ model_name: Optional[str] = None,
76
+ m_cfg: CVModelConfig = CVModelConfig(CVCapabilities.OCR),
75
77
  plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
76
78
  device_id: Optional[str] = None,
77
79
  **kwargs
78
- ) -> 'CVModel':
80
+ ) -> 'CVModel':
79
81
  """Load CV model from configuration, routing to appropriate implementation."""
80
- # Check plugin_id value for routing - handle both enum and string
81
- plugin_value = plugin_id.value if isinstance(plugin_id, PluginID) else plugin_id
82
-
82
+ plugin_value = plugin_id.value if isinstance(
83
+ plugin_id, PluginID) else plugin_id
84
+
83
85
  if plugin_value == "mlx":
84
86
  from nexaai.cv_impl.mlx_cv_impl import MLXCVImpl
85
- return MLXCVImpl._load_from(config, plugin_id, device_id)
87
+ return MLXCVImpl._load_from(local_path, model_name, m_cfg, plugin_id, device_id, **kwargs)
86
88
  else:
87
89
  from nexaai.cv_impl.pybind_cv_impl import PyBindCVImpl
88
- return PyBindCVImpl._load_from(config, plugin_id, device_id)
90
+ return PyBindCVImpl._load_from(local_path, model_name, m_cfg, plugin_id, device_id, **kwargs)
89
91
 
90
92
  @abstractmethod
91
93
  def infer(self, input_image_path: str) -> CVResults:
@@ -1,32 +1,124 @@
1
- from typing import Optional, Union
1
+ from typing import Optional, Union, List
2
+ import os
2
3
 
3
- from nexaai.common import PluginID
4
- from nexaai.cv import CVModel, CVModelConfig, CVResults
4
+ from nexaai.common import PluginID, ModelConfig
5
+ from nexaai.cv import CVModel, CVModelConfig, CVResults, CVResult, BoundingBox, CVCapabilities
6
+ from nexaai.binds import cv_bind, common_bind
7
+ from nexaai.runtime import _ensure_runtime
5
8
 
6
9
 
7
10
  class PyBindCVImpl(CVModel):
8
- def __init__(self):
9
- """Initialize PyBind CV implementation."""
11
+ def __init__(self, handle: any, m_cfg: ModelConfig = ModelConfig()):
12
+ """Private constructor, should not be called directly."""
10
13
  super().__init__()
11
- # TODO: Add PyBind-specific initialization
14
+ self._handle = handle # This is a py::capsule
15
+ self._model_config = None
12
16
 
13
17
  @classmethod
14
18
  def _load_from(cls,
15
- config: CVModelConfig,
19
+ local_path: str, # This is the local path after auto_download_model processing
20
+ model_name: Optional[str] = None,
21
+ m_cfg: CVModelConfig = CVModelConfig(CVCapabilities.OCR),
16
22
  plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
17
- device_id: Optional[str] = None
18
- ) -> 'PyBindCVImpl':
23
+ device_id: Optional[str] = None,
24
+ **kwargs
25
+ ) -> 'PyBindCVImpl':
19
26
  """Load CV model from configuration using PyBind backend."""
20
- # TODO: Implement PyBind CV loading
21
- instance = cls()
22
- return instance
27
+ _ensure_runtime()
28
+
29
+ config = cv_bind.CVModelConfig()
30
+ config.capabilities = cv_bind.CVCapabilities(m_cfg.capabilities)
31
+ if m_cfg.det_model_path is not None:
32
+ config.det_model_path = m_cfg.det_model_path
33
+ else:
34
+ config.det_model_path = local_path
35
+
36
+ print("local_path: ", local_path)
37
+ print("m_cfg.rec_model_path: ", m_cfg.rec_model_path)
38
+ if m_cfg.rec_model_path is not None:
39
+ config.rec_model_path = m_cfg.rec_model_path
40
+ else:
41
+ config.rec_model_path = local_path
42
+ print("config.rec_model_path: ", config.rec_model_path)
43
+
44
+ if m_cfg.char_dict_path is not None:
45
+ config.char_dict_path = m_cfg.char_dict_path
46
+
47
+ if m_cfg.model_path is not None:
48
+ config.model_path = m_cfg.model_path
49
+
50
+ if m_cfg.system_library_path is not None:
51
+ config.system_library_path = m_cfg.system_library_path
52
+
53
+ plugin_id_str = plugin_id.value if isinstance(
54
+ plugin_id, PluginID) else str(plugin_id)
55
+
56
+ model_name_to_use = model_name if model_name else local_path
57
+ handle = cv_bind.ml_cv_create(
58
+ model_name=model_name_to_use,
59
+ config=config,
60
+ plugin_id=plugin_id_str,
61
+ device_id=device_id,
62
+ license_id=None,
63
+ license_key=None
64
+ )
65
+
66
+ return cls(handle, m_cfg)
23
67
 
24
68
  def eject(self):
25
- """Destroy the model and free resources."""
26
- # TODO: Implement PyBind CV cleanup
27
- pass
69
+ """Release the model from memory."""
70
+ # py::capsule handles cleanup automatically
71
+ if hasattr(self, '_handle') and self._handle is not None:
72
+ del self._handle
73
+ self._handle = None
28
74
 
29
75
  def infer(self, input_image_path: str) -> CVResults:
30
76
  """Perform inference on image."""
31
- # TODO: Implement PyBind CV inference
32
- raise NotImplementedError("PyBind CV inference not yet implemented")
77
+ if self._handle is None:
78
+ raise RuntimeError("CV model not loaded. Call _load_from first.")
79
+
80
+ if not os.path.exists(input_image_path):
81
+ raise FileNotFoundError(
82
+ f"Input image not found: {input_image_path}")
83
+
84
+ try:
85
+ # Perform inference using the binding
86
+ result_dict = cv_bind.ml_cv_infer(
87
+ handle=self._handle,
88
+ input_image_path=input_image_path
89
+ )
90
+
91
+ # Convert result dictionary to CVResults
92
+ results = []
93
+ for result_data in result_dict["results"]:
94
+ # Create bounding box if present
95
+ bbox = None
96
+ if "bbox" in result_data and result_data["bbox"] is not None:
97
+ bbox_data = result_data["bbox"]
98
+ bbox = BoundingBox(
99
+ x=bbox_data["x"],
100
+ y=bbox_data["y"],
101
+ width=bbox_data["width"],
102
+ height=bbox_data["height"]
103
+ )
104
+
105
+ # Create CV result
106
+ cv_result = CVResult(
107
+ image_paths=result_data.get("image_paths"),
108
+ image_count=result_data.get("image_count", 0),
109
+ class_id=result_data.get("class_id", 0),
110
+ confidence=result_data.get("confidence", 0.0),
111
+ bbox=bbox,
112
+ text=result_data.get("text"),
113
+ embedding=result_data.get("embedding"),
114
+ embedding_dim=result_data.get("embedding_dim", 0)
115
+ )
116
+ results.append(cv_result)
117
+
118
+ return CVResults(
119
+ results=results,
120
+ result_count=result_dict["result_count"]
121
+ )
122
+
123
+ except Exception as e:
124
+ raise RuntimeError(f"CV inference failed: {str(e)}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nexaai
3
- Version: 1.0.22rc1
3
+ Version: 1.0.23
4
4
  Summary: Python bindings for NexaSDK C-lib backend
5
5
  Author-email: "Nexa AI, Inc." <dev@nexa.ai>
6
6
  Project-URL: Homepage, https://github.com/NexaAI/nexasdk-bridge
@@ -1,10 +1,10 @@
1
1
  nexaai/__init__.py,sha256=gOd7sNsqEESopw_24xgnOSkIRENrk4Fa-RMtmVv62eA,2421
2
- nexaai/_stub.cpython-310-darwin.so,sha256=K9yXY_1DXWCiUmHtVfln03zjB2h6di52_PXDS9RVdP0,49832
3
- nexaai/_version.py,sha256=0q2EJ4saciUBgJlIVBQ8zNjkiCdlgXu4L4drObmfDIE,143
2
+ nexaai/_stub.cpython-310-darwin.so,sha256=waPvCIX3OuCRoo_KRALKlRFLDZPZwcmF9fCzdVhYYUw,49832
3
+ nexaai/_version.py,sha256=j_sMUOs-rlDDzHhGRBuKZSz_Ij3I4oXriuZWuCat46U,139
4
4
  nexaai/asr.py,sha256=wqtq71cxIMGE4KvOIYZebHdWik8dy4LyKrDI98PDvzQ,2294
5
5
  nexaai/base.py,sha256=N8PRgDFA-XPku2vWnQIofQ7ipz3pPlO6f8YZGnuhquE,982
6
6
  nexaai/common.py,sha256=MRWZ6a7pnci_OUHxZRm3YqgKLAtZFD7b88STYDfeIF8,3460
7
- nexaai/cv.py,sha256=gpE3F__6bjh8OQKNJZs-QrBuCxqMj2eH-u6HR90vGZE,3302
7
+ nexaai/cv.py,sha256=WbyFzvByx6hOoR2ZrGSm6i4uG0ubxqeMZ9x71kG6Des,3338
8
8
  nexaai/embedder.py,sha256=lXOT16PEvd_hT23d77dZH38VHNOAk-3JvoOUdQTEaGI,2552
9
9
  nexaai/image_gen.py,sha256=MkGw1HXqqv8cJzbiGERNPKFXfq9vMOlvuq0pgekXw68,4385
10
10
  nexaai/llm.py,sha256=-agVJuj0FOaDvDiT-fFSOpoyVt-MpNudBucsod3Vp1M,3673
@@ -20,8 +20,9 @@ nexaai/asr_impl/pybind_asr_impl.py,sha256=FLOWIph37q_nIiNx8xYi-VnhQ6CrPuc4HFAJZQ
20
20
  nexaai/binds/__init__.py,sha256=2-Rr0NwyWygqwS8Xlxq0BJ2ltyID-WbGuzEYNlSanCI,155
21
21
  nexaai/binds/asr_bind.cpython-310-darwin.so,sha256=QmxLTY6qmHtbkdZlSyvdh7pVh0KP9j1ARtIWJDi_QMs,217096
22
22
  nexaai/binds/common_bind.cpython-310-darwin.so,sha256=BoXByRlNGDaNS1YyZyCF-s7h0vXP9NLPlJMQQ5pqusU,235488
23
+ nexaai/binds/cv_bind.cpython-310-darwin.so,sha256=fG4XpYiIxc4gIqVDE8ig_b5wuiaXSCTv4fcUB1z9aM4,250384
23
24
  nexaai/binds/embedder_bind.cpython-310-darwin.so,sha256=ZOJLzVvTUkbDdBBak1ylOmKx_bwHVzaPvha6RkoLpGo,202032
24
- nexaai/binds/libnexa_bridge.dylib,sha256=M3XBNZthwTzIx7BMRKWT9lkj7P3ErvK3IN4_nf9tHZI,290352
25
+ nexaai/binds/libnexa_bridge.dylib,sha256=yuUZsGawQ_dsYkSmj1_52c9lvCDcJqvXUu0bgDWhtHo,290352
25
26
  nexaai/binds/llm_bind.cpython-310-darwin.so,sha256=-EJUa4rf6nEZUSqKwmB2brSuIdc5OFYOjvqs999ug5E,183096
26
27
  nexaai/binds/rerank_bind.cpython-310-darwin.so,sha256=seJQ1ZpYVR_RCMmBvPSHnLj5LCHX33k5VUFadUkQsvI,200384
27
28
  nexaai/binds/vlm_bind.cpython-310-darwin.so,sha256=IXM3RTJx-rii3DNZCAVY6eKxn9C8TtAMP9i5bi8qA6s,199392
@@ -34,7 +35,7 @@ nexaai/binds/cpu_gpu/libnexa_cpu_gpu.dylib,sha256=9qrrMOlGWM9cWUORg64GfkE_p9aQ1r
34
35
  nexaai/binds/cpu_gpu/libnexa_plugin.dylib,sha256=GiXEXNYePuJRaCtnJw1jrS2dtPcp90qr-IvnrL95dmU,2064152
35
36
  nexaai/cv_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
37
  nexaai/cv_impl/mlx_cv_impl.py,sha256=gKECQOv8iaWwG3bl7xeqVy2NN_9K7tYerIFzfn4eLo4,3228
37
- nexaai/cv_impl/pybind_cv_impl.py,sha256=uSmwBste4cT7c8DQmXzRLmzwDf773PAbXNYWW1UzVls,1064
38
+ nexaai/cv_impl/pybind_cv_impl.py,sha256=YVIgNZe8FaUs6eH4IfirqhAyMy9RXqZL0eqVjGwSfO0,4761
38
39
  nexaai/embedder_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
40
  nexaai/embedder_impl/mlx_embedder_impl.py,sha256=pFPraUAjm9EVvVbwIp1cjbtXUysF5pqxEcK2CAFvcDw,4639
40
41
  nexaai/embedder_impl/pybind_embedder_impl.py,sha256=lFpf0wI2d7kfO2GUyUuUS1U2L_PyZMJVGmAvF8EuQ0g,3653
@@ -401,7 +402,7 @@ nexaai/utils/quantization_utils.py,sha256=FYcNSAKGlBqFDUTx3jSKOr2lnq4nyiyC0ZG8oS
401
402
  nexaai/vlm_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
402
403
  nexaai/vlm_impl/mlx_vlm_impl.py,sha256=sgHqnX5OCSGLccCnTuRiktIbqThNn3AAIvYE2_Dy4TI,10833
403
404
  nexaai/vlm_impl/pybind_vlm_impl.py,sha256=stJKHdhYhBuWUQkky-nHgCv625qDB_1geI3v5BLNGpM,9765
404
- nexaai-1.0.22rc1.dist-info/METADATA,sha256=VFUv5Y64PitLfHWQWvGW_dHdoGpR99_s3dqkD-1lU4o,1187
405
- nexaai-1.0.22rc1.dist-info/WHEEL,sha256=0KYp5feZ1CMUhsfFXKpSQTbSmQbXy4mv6yPPVBXg2EM,110
406
- nexaai-1.0.22rc1.dist-info/top_level.txt,sha256=LRE2YERlrZk2vfuygnSzsEeqSknnZbz3Z1MHyNmBU4w,7
407
- nexaai-1.0.22rc1.dist-info/RECORD,,
405
+ nexaai-1.0.23.dist-info/METADATA,sha256=E_PNlK0fIcVhcTkwQRaaY6TZ36LeRR7bRxFiy8LV7-g,1184
406
+ nexaai-1.0.23.dist-info/WHEEL,sha256=0KYp5feZ1CMUhsfFXKpSQTbSmQbXy4mv6yPPVBXg2EM,110
407
+ nexaai-1.0.23.dist-info/top_level.txt,sha256=LRE2YERlrZk2vfuygnSzsEeqSknnZbz3Z1MHyNmBU4w,7
408
+ nexaai-1.0.23.dist-info/RECORD,,