nexaai 1.0.22__cp310-cp310-macosx_14_0_universal2.whl → 1.0.23__cp310-cp310-macosx_14_0_universal2.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"
4
+ __version__ = "1.0.23"
Binary file
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.22
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=OZuKXZRiNGMjNupMnGLv14pYMIoOzTxHGHflS4zUk2I,66768
3
- nexaai/_version.py,sha256=fWzVuSja_lnFQfiXurvM3Nq0-fbC2d6ueAZkQQ-1E6Q,139
2
+ nexaai/_stub.cpython-310-darwin.so,sha256=8Qjo0gLyVm2O7jvohJd_JP0-7ScQif6dMrm6efSCKJw,66768
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=nr1BqGYRCooj2k5khaIvGG06_GrzudMXa9xa15UQ-88,200768
22
22
  nexaai/binds/common_bind.cpython-310-darwin.so,sha256=zxJuD0nSV--VZKxBfWZUavU7_bHj_JTi0FhkjvG4VJw,235264
23
+ nexaai/binds/cv_bind.cpython-310-darwin.so,sha256=-6Nj7bm03pWVUNEa4jYQW7Y7F5LuFEmK9Dl5nK0GDEU,250640
23
24
  nexaai/binds/embedder_bind.cpython-310-darwin.so,sha256=nn3kINQUNyXIzmcU1olLg8RlkZYyIs_RtIlCk6OH1ds,202064
24
- nexaai/binds/libnexa_bridge.dylib,sha256=SOnKb1axm7bJtwLEqV3DAIN9z0KCZWzABC3X-IQis48,291224
25
+ nexaai/binds/libnexa_bridge.dylib,sha256=uxNHsoxVd5Kdvn045unNpq8McqcYPb5btuQMfcrqTlc,291224
25
26
  nexaai/binds/llm_bind.cpython-310-darwin.so,sha256=YP_GzIPBb4OMNmI-VMYgorx5g31oorcdBI3XQpi3jKI,182784
26
27
  nexaai/binds/rerank_bind.cpython-310-darwin.so,sha256=GJmffOLo9A48S_pMG2CtHyhbamtt97QikSSCXk3LqiM,183920
27
28
  nexaai/binds/vlm_bind.cpython-310-darwin.so,sha256=JEoQbyOkMXVK4WyBCqKBHbyXHtTiTWT18UkZMFvMh4k,182704
@@ -195,14 +196,14 @@ nexaai/binds/nexaml/libmp3lame.0.dylib,sha256=G-21u3MAZ2hiv1fbPEpOUGdToZfLtz2XI6
195
196
  nexaai/binds/nexaml/libmpg123.0.dylib,sha256=L4AgLcdcjGOQkEovUGDCNlH959500i0GkKBhqiHxBY4,306464
196
197
  nexaai/binds/nexaml/libnexa-mm-process.dylib,sha256=WCEgYK13YBfg-DiaGXXJ00-QYo0ucEP-QUS1jVEUR_k,10222392
197
198
  nexaai/binds/nexaml/libnexa-sampling.dylib,sha256=mWJ3jsF4bp3RwWebgjd4PalZqtLiXGK4Y5J9IkYqgvk,7957800
198
- nexaai/binds/nexaml/libnexa_plugin.dylib,sha256=7HglcsNk_2Stbpw22TpvItmPQY3vbQMvu-JOlDWOkHA,267224
199
+ nexaai/binds/nexaml/libnexa_plugin.dylib,sha256=Qkdjyz4hG40BIa8-pngm-m05EeOzrXwFvBKa_0U3EVE,267224
199
200
  nexaai/binds/nexaml/libnexaproc.dylib,sha256=KNAyTwv2Tk94VNbUNFldDbnhQmJwv2ykysfvW_267DY,897248
200
201
  nexaai/binds/nexaml/libomp.dylib,sha256=RcvfaCz0XuqTYtVPFYyUm2V6S9YgUQ0x5pHATr9FnDk,754912
201
202
  nexaai/binds/nexaml/libqwen3-vl.dylib,sha256=zTKPJqAzSsUt4b2DOwkgcjysDSa9tAYY0m2HaxrIlLo,770784
202
203
  nexaai/binds/nexaml/libqwen3vl-vision.dylib,sha256=t0QfNZG5gpvHPBqX-Tdm1qjaXHCVROTtzL5bW78v4-I,490344
203
204
  nexaai/cv_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
204
205
  nexaai/cv_impl/mlx_cv_impl.py,sha256=gKECQOv8iaWwG3bl7xeqVy2NN_9K7tYerIFzfn4eLo4,3228
205
- nexaai/cv_impl/pybind_cv_impl.py,sha256=uSmwBste4cT7c8DQmXzRLmzwDf773PAbXNYWW1UzVls,1064
206
+ nexaai/cv_impl/pybind_cv_impl.py,sha256=YVIgNZe8FaUs6eH4IfirqhAyMy9RXqZL0eqVjGwSfO0,4761
206
207
  nexaai/embedder_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
207
208
  nexaai/embedder_impl/mlx_embedder_impl.py,sha256=pFPraUAjm9EVvVbwIp1cjbtXUysF5pqxEcK2CAFvcDw,4639
208
209
  nexaai/embedder_impl/pybind_embedder_impl.py,sha256=lFpf0wI2d7kfO2GUyUuUS1U2L_PyZMJVGmAvF8EuQ0g,3653
@@ -569,7 +570,7 @@ nexaai/utils/quantization_utils.py,sha256=FYcNSAKGlBqFDUTx3jSKOr2lnq4nyiyC0ZG8oS
569
570
  nexaai/vlm_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
570
571
  nexaai/vlm_impl/mlx_vlm_impl.py,sha256=sgHqnX5OCSGLccCnTuRiktIbqThNn3AAIvYE2_Dy4TI,10833
571
572
  nexaai/vlm_impl/pybind_vlm_impl.py,sha256=stJKHdhYhBuWUQkky-nHgCv625qDB_1geI3v5BLNGpM,9765
572
- nexaai-1.0.22.dist-info/METADATA,sha256=dgjz8lyw-1DssxtFV5wnxMO5P5iPnLVbOElwYtgrzic,1184
573
- nexaai-1.0.22.dist-info/WHEEL,sha256=T2p57lol9__xkoU6aJTyN1Pm43ZpRU3q6km7mIbrAMs,114
574
- nexaai-1.0.22.dist-info/top_level.txt,sha256=LRE2YERlrZk2vfuygnSzsEeqSknnZbz3Z1MHyNmBU4w,7
575
- nexaai-1.0.22.dist-info/RECORD,,
573
+ nexaai-1.0.23.dist-info/METADATA,sha256=E_PNlK0fIcVhcTkwQRaaY6TZ36LeRR7bRxFiy8LV7-g,1184
574
+ nexaai-1.0.23.dist-info/WHEEL,sha256=T2p57lol9__xkoU6aJTyN1Pm43ZpRU3q6km7mIbrAMs,114
575
+ nexaai-1.0.23.dist-info/top_level.txt,sha256=LRE2YERlrZk2vfuygnSzsEeqSknnZbz3Z1MHyNmBU4w,7
576
+ nexaai-1.0.23.dist-info/RECORD,,