cmdbox 0.6.4.1__py3-none-any.whl → 0.6.4.2__py3-none-any.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 cmdbox might be problematic. Click here for more details.
- cmdbox/app/features/cli/cmdbox_vision_install.py +213 -0
- cmdbox/app/features/cli/cmdbox_vision_predict.py +192 -0
- cmdbox/app/features/cli/cmdbox_vision_start.py +230 -0
- cmdbox/app/features/web/cmdbox_web_versions_used.py +1 -1
- cmdbox/version.py +2 -2
- cmdbox/web/voicevox_license_list.txt +41 -0
- {cmdbox-0.6.4.1.dist-info → cmdbox-0.6.4.2.dist-info}/METADATA +1 -1
- {cmdbox-0.6.4.1.dist-info → cmdbox-0.6.4.2.dist-info}/RECORD +12 -33
- cmdbox/app/features/cli/cmdbox_mcp_client.py +0 -174
- cmdbox/app/features/cli/cmdbox_mcp_proxy.py +0 -96
- cmdbox/licenses/LICENSE_SQLAlchemy_2_0_42_MIT.txt +0 -19
- cmdbox/licenses/LICENSE_anyio_4_9_0_MIT_License.txt +0 -20
- cmdbox/licenses/LICENSE_certifi_2025_7_14_Mozilla_Public_License_2_0-MPL_2_0.txt +0 -20
- cmdbox/licenses/LICENSE_charset-normalizer_3_4_2_MIT_License.txt +0 -21
- cmdbox/licenses/LICENSE_cryptography_45_0_5_Apache-2_0_OR_BSD-3-Clause.txt +0 -3
- cmdbox/licenses/LICENSE_fastmcp_2_11_0_Apache_Software_License.txt +0 -201
- cmdbox/licenses/LICENSE_google-adk_1_9_0_Apache_Software_License.txt +0 -202
- cmdbox/licenses/LICENSE_google-api-python-client_2_177_0_Apache_Software_License.txt +0 -201
- cmdbox/licenses/LICENSE_google-cloud-aiplatform_1_106_0_Apache_2_0.txt +0 -202
- cmdbox/licenses/LICENSE_google-genai_1_28_0_Apache_Software_License.txt +0 -202
- cmdbox/licenses/LICENSE_greenlet_3_2_3_MIT_AND_Python-2_0.txt +0 -30
- cmdbox/licenses/LICENSE_huggingface-hub_0_34_3_Apache_Software_License.txt +0 -201
- cmdbox/licenses/LICENSE_litellm_1_74_12_MIT_License.txt +0 -26
- cmdbox/licenses/LICENSE_markdown-it-py_3_0_0_MIT_License.txt +0 -21
- cmdbox/licenses/LICENSE_mcp_1_12_3_MIT_License.txt +0 -21
- cmdbox/licenses/LICENSE_multidict_6_6_3_Apache_License_2_0.txt +0 -13
- cmdbox/licenses/LICENSE_openai_1_98_0_Apache_Software_License.txt +0 -201
- cmdbox/licenses/LICENSE_redis_6_2_0_MIT_License.txt +0 -21
- cmdbox/licenses/LICENSE_rpds-py_0_26_0_MIT.txt +0 -19
- cmdbox/licenses/LICENSE_sphinx-intl_2_3_1_BSD_License.txt +0 -25
- cmdbox/licenses/LICENSE_tenacity_8_5_0_Apache_Software_License.txt +0 -202
- cmdbox/licenses/LICENSE_tiktoken_0_9_0_MIT_License-Copyright-c-2022_OpenAI-Shantanu_Jain-Permission_is_hereby_granted-free_of_charge-to_any_pers.txt +0 -21
- cmdbox/licenses/LICENSE_voicevox_core_0_16_0_MIT.txt +0 -20
- {cmdbox-0.6.4.1.dist-info → cmdbox-0.6.4.2.dist-info}/WHEEL +0 -0
- {cmdbox-0.6.4.1.dist-info → cmdbox-0.6.4.2.dist-info}/entry_points.txt +0 -0
- {cmdbox-0.6.4.1.dist-info → cmdbox-0.6.4.2.dist-info}/licenses/LICENSE +0 -0
- {cmdbox-0.6.4.1.dist-info → cmdbox-0.6.4.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
from cmdbox import version
|
|
2
|
+
from cmdbox.app import common, client, feature
|
|
3
|
+
from cmdbox.app.commons import convert, redis_client
|
|
4
|
+
from cmdbox.app.options import Options
|
|
5
|
+
from cmdbox.app.features.cli import cmdbox_vision_start
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Dict, Any, Tuple, List, Union
|
|
8
|
+
import argparse
|
|
9
|
+
import glob
|
|
10
|
+
import logging
|
|
11
|
+
import pip
|
|
12
|
+
import requests
|
|
13
|
+
import shutil
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class VisionInstall(cmdbox_vision_start.VisionStart):
|
|
19
|
+
def get_mode(self) -> Union[str, List[str]]:
|
|
20
|
+
"""
|
|
21
|
+
この機能のモードを返します
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
Union[str, List[str]]: モード
|
|
25
|
+
"""
|
|
26
|
+
return 'vision'
|
|
27
|
+
|
|
28
|
+
def get_cmd(self):
|
|
29
|
+
"""
|
|
30
|
+
この機能のコマンドを返します
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
str: コマンド
|
|
34
|
+
"""
|
|
35
|
+
return 'install'
|
|
36
|
+
|
|
37
|
+
def get_option(self):
|
|
38
|
+
"""
|
|
39
|
+
この機能のオプションを返します
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
Dict[str, Any]: オプション
|
|
43
|
+
"""
|
|
44
|
+
return dict(
|
|
45
|
+
use_redis=self.USE_REDIS_MEIGHT, nouse_webmode=True, use_agent=False,
|
|
46
|
+
description_ja="画像/動画の推論エンジンをインストールします。",
|
|
47
|
+
description_en="Installs the image/video inference engine.",
|
|
48
|
+
choice=[
|
|
49
|
+
dict(opt="host", type=Options.T_STR, default=self.default_host, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
50
|
+
description_ja="Redisサーバーのサービスホストを指定します。",
|
|
51
|
+
description_en="Specify the service host of the Redis server."),
|
|
52
|
+
dict(opt="port", type=Options.T_INT, default=self.default_port, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
53
|
+
description_ja="Redisサーバーのサービスポートを指定します。",
|
|
54
|
+
description_en="Specify the service port of the Redis server."),
|
|
55
|
+
dict(opt="password", type=Options.T_STR, default=self.default_pass, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
56
|
+
description_ja=f"Redisサーバーのアクセスパスワード(任意)を指定します。省略時は `{self.default_pass}` を使用します。",
|
|
57
|
+
description_en=f"Specify the access password of the Redis server (optional). If omitted, `{self.default_pass}` is used."),
|
|
58
|
+
dict(opt="svname", type=Options.T_STR, default=self.default_svname, required=True, multi=False, hide=True, choice=None, web="readonly",
|
|
59
|
+
description_ja="サーバーのサービス名を指定します。省略時は `server` を使用します。",
|
|
60
|
+
description_en="Specify the service name of the inference server. If omitted, `server` is used."),
|
|
61
|
+
dict(opt="retry_count", type=Options.T_INT, default=3, required=False, multi=False, hide=True, choice=None,
|
|
62
|
+
description_ja="Redisサーバーへの再接続回数を指定します。0以下を指定すると永遠に再接続を行います。",
|
|
63
|
+
description_en="Specifies the number of reconnections to the Redis server.If less than 0 is specified, reconnection is forever."),
|
|
64
|
+
dict(opt="retry_interval", type=Options.T_INT, default=5, required=False, multi=False, hide=True, choice=None,
|
|
65
|
+
description_ja="Redisサーバーに再接続までの秒数を指定します。",
|
|
66
|
+
description_en="Specifies the number of seconds before reconnecting to the Redis server."),
|
|
67
|
+
dict(opt="timeout", type=Options.T_INT, default="300", required=False, multi=False, hide=True, choice=None,
|
|
68
|
+
description_ja="サーバーの応答が返ってくるまでの最大待ち時間を指定。",
|
|
69
|
+
description_en="Specify the maximum waiting time until the server responds."),
|
|
70
|
+
dict(opt="client_only", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[True, False],
|
|
71
|
+
description_ja="サーバーへの接続を行わないようにします。",
|
|
72
|
+
description_en="Do not make connections to the server."),
|
|
73
|
+
dict(opt="vision_engine", type=Options.T_STR, default="sam2", required=True, multi=False, hide=False,
|
|
74
|
+
choice=["sam2"],
|
|
75
|
+
description_ja="使用するVisionエンジンを指定します。",
|
|
76
|
+
description_en="Specify the Vision engine to use."),
|
|
77
|
+
]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def get_svcmd(self):
|
|
81
|
+
"""
|
|
82
|
+
この機能のサーバー側のコマンドを返します
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
str: サーバー側のコマンド
|
|
86
|
+
"""
|
|
87
|
+
return 'vision_install'
|
|
88
|
+
|
|
89
|
+
def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
90
|
+
"""
|
|
91
|
+
この機能の実行を行います
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
logger (logging.Logger): ロガー
|
|
95
|
+
args (argparse.Namespace): 引数
|
|
96
|
+
tm (float): 実行開始時間
|
|
97
|
+
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
101
|
+
"""
|
|
102
|
+
if args.vision_engine is None:
|
|
103
|
+
msg = dict(warn=f"Please specify the --vision_engine option.")
|
|
104
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
105
|
+
return self.RESP_WARN, msg, None
|
|
106
|
+
if args.vision_engine == 'sam2':
|
|
107
|
+
vision_engine_b64 = convert.str2b64str(args.vision_engine)
|
|
108
|
+
if args.client_only:
|
|
109
|
+
# クライアントのみの場合は、サーバーに接続せずに実行
|
|
110
|
+
ret = self.install(common.random_string(), args.vision_engine, logger)
|
|
111
|
+
else:
|
|
112
|
+
cl = client.Client(logger, redis_host=args.host, redis_port=args.port, redis_password=args.password, svname=args.svname)
|
|
113
|
+
ret = cl.redis_cli.send_cmd(self.get_svcmd(), [vision_engine_b64],
|
|
114
|
+
retry_count=args.retry_count, retry_interval=args.retry_interval, timeout=args.timeout, nowait=False)
|
|
115
|
+
common.print_format(ret, False, tm, None, False, pf=pf)
|
|
116
|
+
if 'success' not in ret:
|
|
117
|
+
return self.RESP_WARN, ret, None
|
|
118
|
+
return self.RESP_SUCCESS, ret, None
|
|
119
|
+
|
|
120
|
+
msg = dict(warn=f"Unsupported vision engine: {args.vision_engine}")
|
|
121
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
122
|
+
return self.RESP_WARN, msg, None
|
|
123
|
+
|
|
124
|
+
def is_cluster_redirect(self):
|
|
125
|
+
"""
|
|
126
|
+
クラスター宛のメッセージの場合、メッセージを転送するかどうかを返します
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
bool: メッセージを転送する場合はTrue
|
|
130
|
+
"""
|
|
131
|
+
return False
|
|
132
|
+
|
|
133
|
+
def svrun(self, data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, msg:List[str],
|
|
134
|
+
sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
135
|
+
"""
|
|
136
|
+
この機能のサーバー側の実行を行います
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
data_dir (Path): データディレクトリ
|
|
140
|
+
logger (logging.Logger): ロガー
|
|
141
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
142
|
+
msg (List[str]): 受信メッセージ
|
|
143
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
int: 終了コード
|
|
147
|
+
"""
|
|
148
|
+
if logger.level == logging.DEBUG:
|
|
149
|
+
logger.debug(f"audit write svrun msg: {msg}")
|
|
150
|
+
vision_engine = convert.b64str2str(msg[2])
|
|
151
|
+
ret = self.install(msg[1], vision_engine, logger)
|
|
152
|
+
|
|
153
|
+
if 'success' not in ret:
|
|
154
|
+
redis_cli.rpush(msg[1], ret)
|
|
155
|
+
return self.RESP_WARN
|
|
156
|
+
return self.RESP_SUCCESS
|
|
157
|
+
|
|
158
|
+
def install(self, reskey:str, vision_engine:str, logger:logging.Logger) -> Dict[str, Any]:
|
|
159
|
+
"""
|
|
160
|
+
SAML2をインストールします
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
reskey (str): レスポンスキー
|
|
164
|
+
vision_engine (str): Visionエンジン
|
|
165
|
+
logger (logging.Logger): ロガー
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
Dict[str, Any]: 結果
|
|
169
|
+
"""
|
|
170
|
+
try:
|
|
171
|
+
if vision_engine == 'sam2':
|
|
172
|
+
#===============================================================
|
|
173
|
+
# SAM2のモデルファイルのダウンロード
|
|
174
|
+
sam2_dir = Path(version.__file__).parent / '.sam2' / 'model'
|
|
175
|
+
# すでにダウンローダーが存在する場合は削除
|
|
176
|
+
if sam2_dir.exists():
|
|
177
|
+
shutil.rmtree(sam2_dir)
|
|
178
|
+
for mk, mv in self.VISION_MODEL.items():
|
|
179
|
+
model_file = sam2_dir / mv['path']
|
|
180
|
+
model_file.parent.mkdir(parents=True, exist_ok=True)
|
|
181
|
+
# モデルファイルを保存
|
|
182
|
+
logger.info(f"Downloading.. : {mv['url']}")
|
|
183
|
+
responce = requests.get(f"{mv['url']}", allow_redirects=True)
|
|
184
|
+
if responce.status_code != 200:
|
|
185
|
+
_msg = f"Failed to download SAM2 model: {responce.status_code} {responce.reason}. {mv['url']}"
|
|
186
|
+
logger.error(_msg, exc_info=True)
|
|
187
|
+
return dict(warn=_msg)
|
|
188
|
+
with open(model_file, mode='wb') as f:
|
|
189
|
+
f.write(responce.content)
|
|
190
|
+
#===============================================================
|
|
191
|
+
# SAM2のpythonライブラリのインストール
|
|
192
|
+
whl_url = f'git+https://github.com/facebookresearch/sam2.git'
|
|
193
|
+
# whlファイルをpipでインストール
|
|
194
|
+
if logger.level == logging.DEBUG:
|
|
195
|
+
logger.debug(f"pip install {whl_url}")
|
|
196
|
+
rescode = pip.main(['install', str(whl_url)]) # pipのインストール
|
|
197
|
+
logger.info(f"Install wheel: {whl_url}")
|
|
198
|
+
if rescode != 0:
|
|
199
|
+
_msg = f"Failed to install SAM2 python library: Possible whl not in the environment. {whl_url}"
|
|
200
|
+
logger.error(_msg, exc_info=True)
|
|
201
|
+
return dict(warn=_msg)
|
|
202
|
+
#===============================================================
|
|
203
|
+
# 成功時の処理
|
|
204
|
+
rescode, _msg = (self.RESP_SUCCESS, dict(success=f'Success to install SAM2 python library. {whl_url}'))
|
|
205
|
+
return dict(success=_msg)
|
|
206
|
+
else:
|
|
207
|
+
_msg = f"Unsupported vision engine: {vision_engine}"
|
|
208
|
+
logger.error(_msg, exc_info=True)
|
|
209
|
+
return dict(warn=_msg)
|
|
210
|
+
except Exception as e:
|
|
211
|
+
_msg = f"Failed to install vision engine: {e}"
|
|
212
|
+
logger.warning(_msg, exc_info=True)
|
|
213
|
+
return dict(warn=_msg)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
from cmdbox import version
|
|
2
|
+
from cmdbox.app import common, client, feature
|
|
3
|
+
from cmdbox.app.commons import convert, redis_client
|
|
4
|
+
from cmdbox.app.features.cli import cmdbox_vision_start
|
|
5
|
+
from cmdbox.app.options import Options
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Dict, Any, Tuple, List, Union
|
|
8
|
+
import argparse
|
|
9
|
+
import logging
|
|
10
|
+
import json
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class VisionPredict(cmdbox_vision_start.VisionStart):
|
|
14
|
+
|
|
15
|
+
def get_mode(self) -> Union[str, List[str]]:
|
|
16
|
+
"""
|
|
17
|
+
この機能のモードを返します
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Union[str, List[str]]: モード
|
|
21
|
+
"""
|
|
22
|
+
return 'vision'
|
|
23
|
+
|
|
24
|
+
def get_cmd(self):
|
|
25
|
+
"""
|
|
26
|
+
この機能のコマンドを返します
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
str: コマンド
|
|
30
|
+
"""
|
|
31
|
+
return 'predict'
|
|
32
|
+
|
|
33
|
+
def get_option(self):
|
|
34
|
+
"""
|
|
35
|
+
この機能のオプションを返します
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Dict[str, Any]: オプション
|
|
39
|
+
"""
|
|
40
|
+
return dict(
|
|
41
|
+
use_redis=self.USE_REDIS_MEIGHT, nouse_webmode=False, use_agent=True,
|
|
42
|
+
description_ja="画像/動画の推論を実行します。",
|
|
43
|
+
description_en="Executes inference on images/videos.",
|
|
44
|
+
choice=[
|
|
45
|
+
dict(opt="host", type=Options.T_STR, default=self.default_host, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
46
|
+
description_ja="Redisサーバーのサービスホストを指定します。",
|
|
47
|
+
description_en="Specify the service host of the Redis server."),
|
|
48
|
+
dict(opt="port", type=Options.T_INT, default=self.default_port, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
49
|
+
description_ja="Redisサーバーのサービスポートを指定します。",
|
|
50
|
+
description_en="Specify the service port of the Redis server."),
|
|
51
|
+
dict(opt="password", type=Options.T_STR, default=self.default_pass, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
52
|
+
description_ja=f"Redisサーバーのアクセスパスワード(任意)を指定します。省略時は `{self.default_pass}` を使用します。",
|
|
53
|
+
description_en=f"Specify the access password of the Redis server (optional). If omitted, `{self.default_pass}` is used."),
|
|
54
|
+
dict(opt="svname", type=Options.T_STR, default=self.default_svname, required=True, multi=False, hide=True, choice=None, web="readonly",
|
|
55
|
+
description_ja="サーバーのサービス名を指定します。省略時は `server` を使用します。",
|
|
56
|
+
description_en="Specify the service name of the inference server. If omitted, `server` is used."),
|
|
57
|
+
dict(opt="retry_count", type=Options.T_INT, default=3, required=False, multi=False, hide=True, choice=None,
|
|
58
|
+
description_ja="Redisサーバーへの再接続回数を指定します。0以下を指定すると永遠に再接続を行います。",
|
|
59
|
+
description_en="Specifies the number of reconnections to the Redis server.If less than 0 is specified, reconnection is forever."),
|
|
60
|
+
dict(opt="retry_interval", type=Options.T_INT, default=5, required=False, multi=False, hide=True, choice=None,
|
|
61
|
+
description_ja="Redisサーバーに再接続までの秒数を指定します。",
|
|
62
|
+
description_en="Specifies the number of seconds before reconnecting to the Redis server."),
|
|
63
|
+
dict(opt="timeout", type=Options.T_INT, default="60", required=False, multi=False, hide=True, choice=None,
|
|
64
|
+
description_ja="サーバーの応答が返ってくるまでの最大待ち時間を指定。",
|
|
65
|
+
description_en="Specify the maximum waiting time until the server responds."),
|
|
66
|
+
dict(opt="vision_engine", type=Options.T_STR, default="sam2", required=True, multi=False, hide=False,
|
|
67
|
+
choice=["sam2"],
|
|
68
|
+
choice_show=dict(sam2=["sam2_model", "sam2_point"]),
|
|
69
|
+
description_ja="使用するVisionエンジンを指定します。",
|
|
70
|
+
description_en="Specify the Vision engine to use."),
|
|
71
|
+
dict(opt="sam2_model", type=Options.T_STR, default="092824/sam2.1_hiera_tiny.pt", required=True, multi=False, hide=False,
|
|
72
|
+
choice=[k for k in self.VISION_MODEL.keys() if self.VISION_MODEL[k]['type'] == 'sam2'],
|
|
73
|
+
choice_edit=True,
|
|
74
|
+
description_ja="使用するSAM2モデルを指定します。",
|
|
75
|
+
description_en="Specify the SAM2 model to use."),
|
|
76
|
+
dict(opt="sam2_point", type=Options.T_STR, default=None, required=True, multi=True, hide=False, choice=None,
|
|
77
|
+
description_ja="使用するSAM2モデルのポイントを指定します。 `x,y` の形式で指定してください。",
|
|
78
|
+
description_en="Specify the SAM2 model points to use. Please specify in the format `x,y`."),
|
|
79
|
+
]
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
def get_svcmd(self):
|
|
83
|
+
"""
|
|
84
|
+
この機能のサーバー側のコマンドを返します
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
str: サーバー側のコマンド
|
|
88
|
+
"""
|
|
89
|
+
return 'vision_predict'
|
|
90
|
+
|
|
91
|
+
def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
92
|
+
"""
|
|
93
|
+
この機能の実行を行います
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
logger (logging.Logger): ロガー
|
|
97
|
+
args (argparse.Namespace): 引数
|
|
98
|
+
tm (float): 実行開始時間
|
|
99
|
+
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
103
|
+
"""
|
|
104
|
+
if args.vision_engine is None:
|
|
105
|
+
msg = dict(warn=f"Please specify the --vision_engine option.")
|
|
106
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
107
|
+
return self.RESP_WARN, msg, None
|
|
108
|
+
if args.vision_engine == 'sam2':
|
|
109
|
+
if args.sam2_model is None:
|
|
110
|
+
msg = dict(warn=f"Please specify the --sam2_model option.")
|
|
111
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
112
|
+
return self.RESP_WARN, msg, None
|
|
113
|
+
|
|
114
|
+
vision_engine_b64 = convert.str2b64str(args.vision_engine)
|
|
115
|
+
sam2_model_b64 = convert.str2b64str(args.sam2_model)
|
|
116
|
+
sam2_point_b64 = convert.str2b64str(common.to_str(args.sam2_point))
|
|
117
|
+
|
|
118
|
+
cl = client.Client(logger, redis_host=args.host, redis_port=args.port, redis_password=args.password, svname=args.svname)
|
|
119
|
+
ret = cl.redis_cli.send_cmd(self.get_svcmd(),
|
|
120
|
+
[vision_engine_b64, sam2_model_b64, sam2_point_b64],
|
|
121
|
+
retry_count=args.retry_count, retry_interval=args.retry_interval, timeout=args.timeout, nowait=False)
|
|
122
|
+
common.print_format(ret, False, tm, None, False, pf=pf)
|
|
123
|
+
if 'success' not in ret:
|
|
124
|
+
return self.RESP_WARN, ret, cl
|
|
125
|
+
return self.RESP_SUCCESS, ret, cl
|
|
126
|
+
|
|
127
|
+
msg = dict(warn=f"Unsupported vision engine: {args.vision_engine}")
|
|
128
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
129
|
+
return self.RESP_WARN, msg, None
|
|
130
|
+
|
|
131
|
+
def is_cluster_redirect(self):
|
|
132
|
+
"""
|
|
133
|
+
クラスター宛のメッセージの場合、メッセージを転送するかどうかを返します
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
bool: メッセージを転送する場合はTrue
|
|
137
|
+
"""
|
|
138
|
+
return False
|
|
139
|
+
|
|
140
|
+
def svrun(self, data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, msg:List[str],
|
|
141
|
+
sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
142
|
+
"""
|
|
143
|
+
この機能のサーバー側の実行を行います
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
data_dir (Path): データディレクトリ
|
|
147
|
+
logger (logging.Logger): ロガー
|
|
148
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
149
|
+
msg (List[str]): 受信メッセージ
|
|
150
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
int: 終了コード
|
|
154
|
+
"""
|
|
155
|
+
if logger.level == logging.DEBUG:
|
|
156
|
+
logger.debug(f"audit write svrun msg: {msg}")
|
|
157
|
+
vision_engine = convert.b64str2str(msg[2])
|
|
158
|
+
sam2_model = convert.b64str2str(msg[3])
|
|
159
|
+
sam2_point = json.loads(convert.b64str2str(msg[4]))
|
|
160
|
+
st = self.predict(msg[1], vision_engine, sam2_model, sam2_point, data_dir, logger, redis_cli, sessions)
|
|
161
|
+
return st
|
|
162
|
+
|
|
163
|
+
def predict(self, reskey:str, vision_engine:str, sam2_model:str, sam2_point:List[List[int]], data_dir:Path, logger:logging.Logger,
|
|
164
|
+
redis_cli:redis_client.RedisClient, sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
165
|
+
"""
|
|
166
|
+
SAM2のモデルを使用して指定したポイントのマスクを取得します
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
reskey (str): レスポンスキー
|
|
170
|
+
vision_engine (str): Visionエンジン
|
|
171
|
+
sam2_model (str): SAM2モデル
|
|
172
|
+
sam2_point (List[List[int,int]]): SAM2モデルのポイント
|
|
173
|
+
data_dir (Path): データディレクトリ
|
|
174
|
+
logger (logging.Logger): ロガー
|
|
175
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
176
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
int: レスポンスコード
|
|
180
|
+
"""
|
|
181
|
+
try:
|
|
182
|
+
if vision_engine == 'sam2':
|
|
183
|
+
raise NotImplementedError("SAM2 model is not implemented yet.")
|
|
184
|
+
else:
|
|
185
|
+
logger.warning(f"Unsupported vision engine: {vision_engine}")
|
|
186
|
+
redis_cli.rpush(reskey, dict(warn=f"Unsupported vision engine: {vision_engine}"))
|
|
187
|
+
return self.RESP_WARN
|
|
188
|
+
|
|
189
|
+
except Exception as e:
|
|
190
|
+
logger.warning(f"Failed to start: {e}", exc_info=True)
|
|
191
|
+
redis_cli.rpush(reskey, dict(warn=f"Failed to start: {e}"))
|
|
192
|
+
return self.RESP_WARN
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
from cmdbox import version
|
|
2
|
+
from cmdbox.app import common, client, feature
|
|
3
|
+
from cmdbox.app.commons import convert, redis_client
|
|
4
|
+
from cmdbox.app.options import Options
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Dict, Any, Tuple, List, Union
|
|
7
|
+
import argparse
|
|
8
|
+
import logging
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class VisionStart(feature.UnsupportEdgeFeature):
|
|
12
|
+
VISION_MODEL = dict()
|
|
13
|
+
VISION_MODEL['092824/sam2.1_hiera_tiny'] = dict(type='sam2',
|
|
14
|
+
path='092824/sam2.1_hiera_tiny.pt',
|
|
15
|
+
conf='configs/sam2.1/sam2.1_hiera_t.yaml',
|
|
16
|
+
url='https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_tiny.pt')
|
|
17
|
+
VISION_MODEL['092824/sam2.1_hiera_small'] = dict(type='sam2',
|
|
18
|
+
path='092824/sam2.1_hiera_small.pt',
|
|
19
|
+
conf='configs/sam2.1/sam2.1_hiera_s.yaml',
|
|
20
|
+
url='https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_small.pt')
|
|
21
|
+
VISION_MODEL['092824/sam2.1_hiera_base_plus'] = dict(type='sam2',
|
|
22
|
+
path='092824/sam2.1_hiera_base_plus.pt',
|
|
23
|
+
conf='configs/sam2.1/sam2.1_hiera_b+.yaml',
|
|
24
|
+
url='https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt')
|
|
25
|
+
VISION_MODEL['092824/sam2.1_hiera_large'] = dict(type='sam2',
|
|
26
|
+
path='092824/sam2.1_hiera_large.pt',
|
|
27
|
+
conf='configs/sam2.1/sam2.1_hiera_l.yaml',
|
|
28
|
+
url='https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt')
|
|
29
|
+
|
|
30
|
+
def get_mode(self) -> Union[str, List[str]]:
|
|
31
|
+
"""
|
|
32
|
+
この機能のモードを返します
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Union[str, List[str]]: モード
|
|
36
|
+
"""
|
|
37
|
+
return 'vision'
|
|
38
|
+
|
|
39
|
+
def get_cmd(self):
|
|
40
|
+
"""
|
|
41
|
+
この機能のコマンドを返します
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
str: コマンド
|
|
45
|
+
"""
|
|
46
|
+
return 'start'
|
|
47
|
+
|
|
48
|
+
def get_option(self):
|
|
49
|
+
"""
|
|
50
|
+
この機能のオプションを返します
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
Dict[str, Any]: オプション
|
|
54
|
+
"""
|
|
55
|
+
return dict(
|
|
56
|
+
use_redis=self.USE_REDIS_MEIGHT, nouse_webmode=False, use_agent=True,
|
|
57
|
+
description_ja="画像/動画の推論を開始します。",
|
|
58
|
+
description_en="Starts inference on images/videos.",
|
|
59
|
+
choice=[
|
|
60
|
+
dict(opt="host", type=Options.T_STR, default=self.default_host, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
61
|
+
description_ja="Redisサーバーのサービスホストを指定します。",
|
|
62
|
+
description_en="Specify the service host of the Redis server."),
|
|
63
|
+
dict(opt="port", type=Options.T_INT, default=self.default_port, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
64
|
+
description_ja="Redisサーバーのサービスポートを指定します。",
|
|
65
|
+
description_en="Specify the service port of the Redis server."),
|
|
66
|
+
dict(opt="password", type=Options.T_STR, default=self.default_pass, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
67
|
+
description_ja=f"Redisサーバーのアクセスパスワード(任意)を指定します。省略時は `{self.default_pass}` を使用します。",
|
|
68
|
+
description_en=f"Specify the access password of the Redis server (optional). If omitted, `{self.default_pass}` is used."),
|
|
69
|
+
dict(opt="svname", type=Options.T_STR, default=self.default_svname, required=True, multi=False, hide=True, choice=None, web="readonly",
|
|
70
|
+
description_ja="サーバーのサービス名を指定します。省略時は `server` を使用します。",
|
|
71
|
+
description_en="Specify the service name of the inference server. If omitted, `server` is used."),
|
|
72
|
+
dict(opt="retry_count", type=Options.T_INT, default=3, required=False, multi=False, hide=True, choice=None,
|
|
73
|
+
description_ja="Redisサーバーへの再接続回数を指定します。0以下を指定すると永遠に再接続を行います。",
|
|
74
|
+
description_en="Specifies the number of reconnections to the Redis server.If less than 0 is specified, reconnection is forever."),
|
|
75
|
+
dict(opt="retry_interval", type=Options.T_INT, default=5, required=False, multi=False, hide=True, choice=None,
|
|
76
|
+
description_ja="Redisサーバーに再接続までの秒数を指定します。",
|
|
77
|
+
description_en="Specifies the number of seconds before reconnecting to the Redis server."),
|
|
78
|
+
dict(opt="timeout", type=Options.T_INT, default="60", required=False, multi=False, hide=True, choice=None,
|
|
79
|
+
description_ja="サーバーの応答が返ってくるまでの最大待ち時間を指定。",
|
|
80
|
+
description_en="Specify the maximum waiting time until the server responds."),
|
|
81
|
+
dict(opt="vision_engine", type=Options.T_STR, default="sam2", required=True, multi=False, hide=False,
|
|
82
|
+
choice=["sam2"],
|
|
83
|
+
choice_show=dict(sam2=["sam2_model"]),
|
|
84
|
+
description_ja="使用するVisionエンジンを指定します。",
|
|
85
|
+
description_en="Specify the Vision engine to use."),
|
|
86
|
+
dict(opt="sam2_model", type=Options.T_STR, default="092824/sam2.1_hiera_tiny.pt", required=True, multi=False, hide=False,
|
|
87
|
+
choice=[k for k in self.VISION_MODEL.keys() if self.VISION_MODEL[k]['type'] == 'sam2'],
|
|
88
|
+
choice_edit=True,
|
|
89
|
+
description_ja="使用するSAM2モデルを指定します。",
|
|
90
|
+
description_en="Specify the SAM2 model to use."),
|
|
91
|
+
]
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def get_svcmd(self):
|
|
95
|
+
"""
|
|
96
|
+
この機能のサーバー側のコマンドを返します
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
str: サーバー側のコマンド
|
|
100
|
+
"""
|
|
101
|
+
return 'vision_start'
|
|
102
|
+
|
|
103
|
+
def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
104
|
+
"""
|
|
105
|
+
この機能の実行を行います
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
logger (logging.Logger): ロガー
|
|
109
|
+
args (argparse.Namespace): 引数
|
|
110
|
+
tm (float): 実行開始時間
|
|
111
|
+
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
115
|
+
"""
|
|
116
|
+
if args.vision_engine is None:
|
|
117
|
+
msg = dict(warn=f"Please specify the --vision_engine option.")
|
|
118
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
119
|
+
return self.RESP_WARN, msg, None
|
|
120
|
+
if args.vision_engine == 'sam2':
|
|
121
|
+
if args.sam2_model is None:
|
|
122
|
+
msg = dict(warn=f"Please specify the --sam2_model option.")
|
|
123
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
124
|
+
return self.RESP_WARN, msg, None
|
|
125
|
+
|
|
126
|
+
vision_engine_b64 = convert.str2b64str(args.vision_engine)
|
|
127
|
+
sam2_model_b64 = convert.str2b64str(args.sam2_model)
|
|
128
|
+
cl = client.Client(logger, redis_host=args.host, redis_port=args.port, redis_password=args.password, svname=args.svname)
|
|
129
|
+
ret = cl.redis_cli.send_cmd(self.get_svcmd(),
|
|
130
|
+
[vision_engine_b64, sam2_model_b64],
|
|
131
|
+
retry_count=args.retry_count, retry_interval=args.retry_interval, timeout=args.timeout, nowait=False)
|
|
132
|
+
common.print_format(ret, False, tm, None, False, pf=pf)
|
|
133
|
+
if 'success' not in ret:
|
|
134
|
+
return self.RESP_WARN, ret, cl
|
|
135
|
+
return self.RESP_SUCCESS, ret, cl
|
|
136
|
+
|
|
137
|
+
msg = dict(warn=f"Unsupported vision engine: {args.vision_engine}")
|
|
138
|
+
common.print_format(msg, False, tm, args.output_json, args.output_json_append, pf=pf)
|
|
139
|
+
return self.RESP_WARN, msg, None
|
|
140
|
+
|
|
141
|
+
def is_cluster_redirect(self):
|
|
142
|
+
"""
|
|
143
|
+
クラスター宛のメッセージの場合、メッセージを転送するかどうかを返します
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
bool: メッセージを転送する場合はTrue
|
|
147
|
+
"""
|
|
148
|
+
return True
|
|
149
|
+
|
|
150
|
+
def svrun(self, data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, msg:List[str],
|
|
151
|
+
sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
152
|
+
"""
|
|
153
|
+
この機能のサーバー側の実行を行います
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
data_dir (Path): データディレクトリ
|
|
157
|
+
logger (logging.Logger): ロガー
|
|
158
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
159
|
+
msg (List[str]): 受信メッセージ
|
|
160
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
int: 終了コード
|
|
164
|
+
"""
|
|
165
|
+
if logger.level == logging.DEBUG:
|
|
166
|
+
logger.debug(f"audit write svrun msg: {msg}")
|
|
167
|
+
vision_engine = convert.b64str2str(msg[2])
|
|
168
|
+
sam2_model = convert.b64str2str(msg[3])
|
|
169
|
+
st = self.start(msg[1], vision_engine, sam2_model, data_dir, logger, redis_cli, sessions)
|
|
170
|
+
return st
|
|
171
|
+
|
|
172
|
+
def start(self, reskey:str, vision_engine:str, sam2_model:str, data_dir:Path, logger:logging.Logger,
|
|
173
|
+
redis_cli:redis_client.RedisClient, sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
174
|
+
"""
|
|
175
|
+
SAM2のモデルを開始します
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
reskey (str): レスポンスキー
|
|
179
|
+
vision_engine (str): Visionエンジン
|
|
180
|
+
sam2_model (str): SAM2モデル
|
|
181
|
+
data_dir (Path): データディレクトリ
|
|
182
|
+
logger (logging.Logger): ロガー
|
|
183
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
184
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
int: レスポンスコード
|
|
188
|
+
"""
|
|
189
|
+
try:
|
|
190
|
+
if vision_engine == 'sam2':
|
|
191
|
+
#===============================================================
|
|
192
|
+
# SAM2モデルの初期化
|
|
193
|
+
from sam2.build_sam import build_sam2
|
|
194
|
+
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
|
195
|
+
#from sam2.sam2_video_predictor import SAM2VideoPredictor
|
|
196
|
+
import torch
|
|
197
|
+
|
|
198
|
+
sam2_dir = Path(version.__file__).parent / '.sam2' / 'model'
|
|
199
|
+
if not sam2_dir.exists():
|
|
200
|
+
logger.error(f"Failed to start SAM2 model: sam2 directory does not exist: {sam2_dir}")
|
|
201
|
+
redis_cli.rpush(reskey, dict(warn=f"Failed to start SAM2 model: sam2 directory does not exist: {sam2_dir}"))
|
|
202
|
+
return self.RESP_WARN
|
|
203
|
+
|
|
204
|
+
model_file = sam2_dir / self.VISION_MODEL[sam2_model]['path']
|
|
205
|
+
config_file = self.VISION_MODEL[sam2_model]['conf']
|
|
206
|
+
if not model_file.exists():
|
|
207
|
+
logger.error(f"Failed to start SAM2 model: model file does not exist: {model_file}")
|
|
208
|
+
redis_cli.rpush(reskey, dict(warn=f"Failed to start SAM2 model: model file does not exist: {model_file}"))
|
|
209
|
+
return self.RESP_WARN
|
|
210
|
+
|
|
211
|
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
212
|
+
# vvmファイルの読込み
|
|
213
|
+
predictor = SAM2ImagePredictor(build_sam2(config_file, model_file, device=device))
|
|
214
|
+
sessions[sam2_model] = dict(
|
|
215
|
+
info=self.VISION_MODEL[sam2_model].copy(),
|
|
216
|
+
predictor=predictor,
|
|
217
|
+
)
|
|
218
|
+
#===============================================================
|
|
219
|
+
# 成功時の処理
|
|
220
|
+
rescode, msg = (self.RESP_SUCCESS, dict(success=f'Success to start SAM2. Model: {sam2_model}'))
|
|
221
|
+
redis_cli.rpush(reskey, msg)
|
|
222
|
+
return rescode
|
|
223
|
+
else:
|
|
224
|
+
logger.warning(f"Unsupported vision engine: {vision_engine}")
|
|
225
|
+
redis_cli.rpush(reskey, dict(warn=f"Unsupported vision engine: {vision_engine}"))
|
|
226
|
+
return self.RESP_WARN
|
|
227
|
+
except Exception as e:
|
|
228
|
+
logger.warning(f"Failed to start: {e}", exc_info=True)
|
|
229
|
+
redis_cli.rpush(reskey, dict(warn=f"Failed to start: {e}"))
|
|
230
|
+
return self.RESP_WARN
|
|
@@ -25,7 +25,7 @@ class VersionsUsed(feature.WebFeature):
|
|
|
25
25
|
for i, line in enumerate(f.readlines()):
|
|
26
26
|
parts = line.strip().split('\t')
|
|
27
27
|
ret.append(parts)
|
|
28
|
-
with open(Path(cmdbox.__file__).parent / '
|
|
28
|
+
with open(Path(cmdbox.__file__).parent / 'web' / 'voicevox_license_list.txt', 'r', encoding='utf-8') as f:
|
|
29
29
|
for i, line in enumerate(f.readlines()):
|
|
30
30
|
parts = line.strip().split('\t')
|
|
31
31
|
ret.append(parts)
|
cmdbox/version.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import datetime
|
|
2
2
|
|
|
3
|
-
dt_now = datetime.datetime(2025, 8,
|
|
3
|
+
dt_now = datetime.datetime(2025, 8, 16)
|
|
4
4
|
days_ago = (datetime.datetime.now() - dt_now).days
|
|
5
5
|
__appid__ = 'cmdbox'
|
|
6
6
|
__title__ = 'cmdbox (Command Development Application)'
|
|
7
|
-
__version__ = '0.6.4.
|
|
7
|
+
__version__ = '0.6.4.2'
|
|
8
8
|
__copyright__ = f'Copyright © 2023-{dt_now.strftime("%Y")} hamacom2004jp'
|
|
9
9
|
__pypiurl__ = 'https://pypi.org/project/cmdbox/'
|
|
10
10
|
__srcurl__ = 'https://github.com/hamacom2004jp/cmdbox'
|