nexaai 1.0.21rc11__cp310-cp310-macosx_14_0_universal2.whl → 1.0.21rc12__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.
- nexaai/_stub.cpython-310-darwin.so +0 -0
- nexaai/_version.py +1 -1
- nexaai/asr.py +8 -5
- nexaai/asr_impl/pybind_asr_impl.py +98 -15
- nexaai/binds/__init__.py +1 -0
- nexaai/binds/asr_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/libnexa_bridge.dylib +0 -0
- {nexaai-1.0.21rc11.dist-info → nexaai-1.0.21rc12.dist-info}/METADATA +1 -1
- {nexaai-1.0.21rc11.dist-info → nexaai-1.0.21rc12.dist-info}/RECORD +11 -10
- {nexaai-1.0.21rc11.dist-info → nexaai-1.0.21rc12.dist-info}/WHEEL +0 -0
- {nexaai-1.0.21rc11.dist-info → nexaai-1.0.21rc12.dist-info}/top_level.txt +0 -0
|
Binary file
|
nexaai/_version.py
CHANGED
nexaai/asr.py
CHANGED
|
@@ -3,7 +3,7 @@ from abc import abstractmethod
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
|
|
5
5
|
from nexaai.base import BaseModel
|
|
6
|
-
from nexaai.common import PluginID
|
|
6
|
+
from nexaai.common import PluginID, ModelConfig
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
@dataclass
|
|
@@ -25,15 +25,17 @@ class ASRResult:
|
|
|
25
25
|
class ASR(BaseModel):
|
|
26
26
|
"""Abstract base class for Automatic Speech Recognition models."""
|
|
27
27
|
|
|
28
|
-
def __init__(self):
|
|
28
|
+
def __init__(self, m_cfg: ModelConfig = ModelConfig()):
|
|
29
29
|
"""Initialize base ASR class."""
|
|
30
|
-
|
|
30
|
+
self._m_cfg = m_cfg
|
|
31
31
|
|
|
32
32
|
@classmethod
|
|
33
33
|
def _load_from(cls,
|
|
34
34
|
model_path: str,
|
|
35
|
+
model_name: Optional[str] = None,
|
|
35
36
|
tokenizer_path: Optional[str] = None,
|
|
36
37
|
language: Optional[str] = None,
|
|
38
|
+
m_cfg: ModelConfig = ModelConfig(),
|
|
37
39
|
plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
|
|
38
40
|
device_id: Optional[str] = None,
|
|
39
41
|
**kwargs
|
|
@@ -44,10 +46,11 @@ class ASR(BaseModel):
|
|
|
44
46
|
|
|
45
47
|
if plugin_value == "mlx":
|
|
46
48
|
from nexaai.asr_impl.mlx_asr_impl import MLXASRImpl
|
|
47
|
-
return MLXASRImpl._load_from(model_path, tokenizer_path, language, plugin_id, device_id)
|
|
49
|
+
return MLXASRImpl._load_from(model_path, model_name, tokenizer_path, language, m_cfg, plugin_id, device_id)
|
|
48
50
|
else:
|
|
49
51
|
from nexaai.asr_impl.pybind_asr_impl import PyBindASRImpl
|
|
50
|
-
return PyBindASRImpl._load_from(model_path, tokenizer_path, language, plugin_id, device_id)
|
|
52
|
+
return PyBindASRImpl._load_from(model_path, model_name, tokenizer_path, language, m_cfg, plugin_id, device_id)
|
|
53
|
+
|
|
51
54
|
|
|
52
55
|
@abstractmethod
|
|
53
56
|
def transcribe(
|
|
@@ -1,32 +1,78 @@
|
|
|
1
1
|
from typing import List, Optional, Union
|
|
2
2
|
|
|
3
|
-
from nexaai.common import PluginID
|
|
3
|
+
from nexaai.common import PluginID, ModelConfig
|
|
4
4
|
from nexaai.asr import ASR, ASRConfig, ASRResult
|
|
5
|
+
from nexaai.binds import asr_bind, common_bind
|
|
6
|
+
from nexaai.runtime import _ensure_runtime
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
class PyBindASRImpl(ASR):
|
|
8
|
-
def __init__(self):
|
|
9
|
-
"""
|
|
10
|
-
super().__init__()
|
|
11
|
-
#
|
|
10
|
+
def __init__(self, handle: any, m_cfg: ModelConfig = ModelConfig()):
|
|
11
|
+
"""Private constructor, should not be called directly."""
|
|
12
|
+
super().__init__(m_cfg)
|
|
13
|
+
self._handle = handle # This is a py::capsule
|
|
14
|
+
self._model_config = None
|
|
12
15
|
|
|
13
16
|
@classmethod
|
|
14
17
|
def _load_from(cls,
|
|
15
18
|
model_path: str,
|
|
19
|
+
model_name: Optional[str] = None,
|
|
16
20
|
tokenizer_path: Optional[str] = None,
|
|
17
21
|
language: Optional[str] = None,
|
|
22
|
+
m_cfg: ModelConfig = ModelConfig(),
|
|
18
23
|
plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
|
|
19
24
|
device_id: Optional[str] = None
|
|
20
25
|
) -> 'PyBindASRImpl':
|
|
21
26
|
"""Load ASR model from local path using PyBind backend."""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
_ensure_runtime()
|
|
28
|
+
|
|
29
|
+
# Create model config
|
|
30
|
+
config = common_bind.ModelConfig()
|
|
31
|
+
|
|
32
|
+
config.n_ctx = m_cfg.n_ctx
|
|
33
|
+
if m_cfg.n_threads is not None:
|
|
34
|
+
config.n_threads = m_cfg.n_threads
|
|
35
|
+
if m_cfg.n_threads_batch is not None:
|
|
36
|
+
config.n_threads_batch = m_cfg.n_threads_batch
|
|
37
|
+
if m_cfg.n_batch is not None:
|
|
38
|
+
config.n_batch = m_cfg.n_batch
|
|
39
|
+
if m_cfg.n_ubatch is not None:
|
|
40
|
+
config.n_ubatch = m_cfg.n_ubatch
|
|
41
|
+
if m_cfg.n_seq_max is not None:
|
|
42
|
+
config.n_seq_max = m_cfg.n_seq_max
|
|
43
|
+
config.n_gpu_layers = m_cfg.n_gpu_layers
|
|
44
|
+
|
|
45
|
+
# handle chat template strings
|
|
46
|
+
if m_cfg.chat_template_path:
|
|
47
|
+
config.chat_template_path = m_cfg.chat_template_path
|
|
48
|
+
|
|
49
|
+
if m_cfg.chat_template_content:
|
|
50
|
+
config.chat_template_content = m_cfg.chat_template_content
|
|
51
|
+
|
|
52
|
+
# Convert plugin_id to string
|
|
53
|
+
plugin_id_str = plugin_id.value if isinstance(plugin_id, PluginID) else str(plugin_id)
|
|
54
|
+
|
|
55
|
+
# Create ASR handle using the binding
|
|
56
|
+
handle = asr_bind.ml_asr_create(
|
|
57
|
+
model_path=model_path,
|
|
58
|
+
model_name=model_name,
|
|
59
|
+
tokenizer_path=tokenizer_path,
|
|
60
|
+
model_config=config,
|
|
61
|
+
language=language,
|
|
62
|
+
plugin_id=plugin_id_str,
|
|
63
|
+
device_id=device_id,
|
|
64
|
+
license_id=None, # Optional
|
|
65
|
+
license_key=None # Optional
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return cls(handle, m_cfg)
|
|
25
69
|
|
|
26
70
|
def eject(self):
|
|
27
|
-
"""
|
|
28
|
-
#
|
|
29
|
-
|
|
71
|
+
"""Release the model from memory."""
|
|
72
|
+
# py::capsule handles cleanup automatically
|
|
73
|
+
if hasattr(self, '_handle') and self._handle is not None:
|
|
74
|
+
del self._handle
|
|
75
|
+
self._handle = None
|
|
30
76
|
|
|
31
77
|
def transcribe(
|
|
32
78
|
self,
|
|
@@ -35,10 +81,47 @@ class PyBindASRImpl(ASR):
|
|
|
35
81
|
config: Optional[ASRConfig] = None,
|
|
36
82
|
) -> ASRResult:
|
|
37
83
|
"""Transcribe audio file to text."""
|
|
38
|
-
|
|
39
|
-
|
|
84
|
+
if self._handle is None:
|
|
85
|
+
raise RuntimeError("ASR model not loaded. Call _load_from first.")
|
|
86
|
+
|
|
87
|
+
# Convert ASRConfig to binding format if provided
|
|
88
|
+
asr_config = None
|
|
89
|
+
if config:
|
|
90
|
+
asr_config = asr_bind.ASRConfig()
|
|
91
|
+
asr_config.timestamps = config.timestamps
|
|
92
|
+
asr_config.beam_size = config.beam_size
|
|
93
|
+
asr_config.stream = config.stream
|
|
94
|
+
|
|
95
|
+
# Perform transcription using the binding
|
|
96
|
+
result_dict = asr_bind.ml_asr_transcribe(
|
|
97
|
+
handle=self._handle,
|
|
98
|
+
audio_path=audio_path,
|
|
99
|
+
language=language,
|
|
100
|
+
config=asr_config
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Convert result to ASRResult
|
|
104
|
+
transcript = result_dict.get("transcript", "")
|
|
105
|
+
confidence_scores = result_dict.get("confidence_scores")
|
|
106
|
+
timestamps = result_dict.get("timestamps")
|
|
107
|
+
|
|
108
|
+
# Convert timestamps to the expected format
|
|
109
|
+
timestamp_pairs = []
|
|
110
|
+
if timestamps:
|
|
111
|
+
for start, end in timestamps:
|
|
112
|
+
timestamp_pairs.append((float(start), float(end)))
|
|
113
|
+
|
|
114
|
+
return ASRResult(
|
|
115
|
+
transcript=transcript,
|
|
116
|
+
confidence_scores=confidence_scores or [],
|
|
117
|
+
timestamps=timestamp_pairs
|
|
118
|
+
)
|
|
40
119
|
|
|
41
120
|
def list_supported_languages(self) -> List[str]:
|
|
42
121
|
"""List supported languages."""
|
|
43
|
-
|
|
44
|
-
|
|
122
|
+
if self._handle is None:
|
|
123
|
+
raise RuntimeError("ASR model not loaded. Call _load_from first.")
|
|
124
|
+
|
|
125
|
+
# Get supported languages using the binding
|
|
126
|
+
languages = asr_bind.ml_asr_list_supported_languages(handle=self._handle)
|
|
127
|
+
return languages
|
nexaai/binds/__init__.py
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
nexaai/__init__.py,sha256=gOd7sNsqEESopw_24xgnOSkIRENrk4Fa-RMtmVv62eA,2421
|
|
2
|
-
nexaai/_stub.cpython-310-darwin.so,sha256=
|
|
3
|
-
nexaai/_version.py,sha256=
|
|
4
|
-
nexaai/asr.py,sha256=
|
|
2
|
+
nexaai/_stub.cpython-310-darwin.so,sha256=LWfONyxO5innYI-hcs69dkucsuoUQL0vumoCOKwOKVA,66768
|
|
3
|
+
nexaai/_version.py,sha256=KA0_ep8LMLIu4v4BoECwDNI510xSHEzGEsb1IyR4iN8,144
|
|
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
7
|
nexaai/cv.py,sha256=gpE3F__6bjh8OQKNJZs-QrBuCxqMj2eH-u6HR90vGZE,3302
|
|
@@ -16,11 +16,12 @@ nexaai/tts.py,sha256=jvgDZIyo47NBDny6z74IQT2SDDVo7Mpp-QZwl6YxARU,2196
|
|
|
16
16
|
nexaai/vlm.py,sha256=LUrd1_SGHOsYpWyUymX93oEIsNJv7XzHIHo4hBZOhQA,4800
|
|
17
17
|
nexaai/asr_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
nexaai/asr_impl/mlx_asr_impl.py,sha256=eosd8-TIWAOwV0HltmoFrLwzXHcU4jyxtncvuZE9pgA,3257
|
|
19
|
-
nexaai/asr_impl/pybind_asr_impl.py,sha256=
|
|
20
|
-
nexaai/binds/__init__.py,sha256=
|
|
19
|
+
nexaai/asr_impl/pybind_asr_impl.py,sha256=FLOWIph37q_nIiNx8xYi-VnhQ6CrPuc4HFAJZQKc42w,4680
|
|
20
|
+
nexaai/binds/__init__.py,sha256=2-Rr0NwyWygqwS8Xlxq0BJ2ltyID-WbGuzEYNlSanCI,155
|
|
21
|
+
nexaai/binds/asr_bind.cpython-310-darwin.so,sha256=nr1BqGYRCooj2k5khaIvGG06_GrzudMXa9xa15UQ-88,200768
|
|
21
22
|
nexaai/binds/common_bind.cpython-310-darwin.so,sha256=zxJuD0nSV--VZKxBfWZUavU7_bHj_JTi0FhkjvG4VJw,235264
|
|
22
23
|
nexaai/binds/embedder_bind.cpython-310-darwin.so,sha256=nn3kINQUNyXIzmcU1olLg8RlkZYyIs_RtIlCk6OH1ds,202064
|
|
23
|
-
nexaai/binds/libnexa_bridge.dylib,sha256=
|
|
24
|
+
nexaai/binds/libnexa_bridge.dylib,sha256=M3RoPffXWjlWwz67ZgglEoyTupLIDv1OM833ULNVoyY,272648
|
|
24
25
|
nexaai/binds/llm_bind.cpython-310-darwin.so,sha256=YShsXbe_n2N05joMmTnZXaXh9gM9LGdcmuWUxUc5plI,182784
|
|
25
26
|
nexaai/binds/rerank_bind.cpython-310-darwin.so,sha256=GJmffOLo9A48S_pMG2CtHyhbamtt97QikSSCXk3LqiM,183920
|
|
26
27
|
nexaai/binds/vlm_bind.cpython-310-darwin.so,sha256=JEoQbyOkMXVK4WyBCqKBHbyXHtTiTWT18UkZMFvMh4k,182704
|
|
@@ -568,7 +569,7 @@ nexaai/utils/quantization_utils.py,sha256=FYcNSAKGlBqFDUTx3jSKOr2lnq4nyiyC0ZG8oS
|
|
|
568
569
|
nexaai/vlm_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
569
570
|
nexaai/vlm_impl/mlx_vlm_impl.py,sha256=sgHqnX5OCSGLccCnTuRiktIbqThNn3AAIvYE2_Dy4TI,10833
|
|
570
571
|
nexaai/vlm_impl/pybind_vlm_impl.py,sha256=stJKHdhYhBuWUQkky-nHgCv625qDB_1geI3v5BLNGpM,9765
|
|
571
|
-
nexaai-1.0.
|
|
572
|
-
nexaai-1.0.
|
|
573
|
-
nexaai-1.0.
|
|
574
|
-
nexaai-1.0.
|
|
572
|
+
nexaai-1.0.21rc12.dist-info/METADATA,sha256=c7oNlxJI7YWk4xaImnDQFtl4SyC5aVEN2Jlpu6PCAJ8,1188
|
|
573
|
+
nexaai-1.0.21rc12.dist-info/WHEEL,sha256=T2p57lol9__xkoU6aJTyN1Pm43ZpRU3q6km7mIbrAMs,114
|
|
574
|
+
nexaai-1.0.21rc12.dist-info/top_level.txt,sha256=LRE2YERlrZk2vfuygnSzsEeqSknnZbz3Z1MHyNmBU4w,7
|
|
575
|
+
nexaai-1.0.21rc12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|