👍️[Update] Model : AI モデルのダウンロード方法を修正
- AIモデルのダウンロード済み確認辞書を追加 - selectable_ctranslate2_weight_type_dict - selectable_whisper_weight_type_dict - AIモデルダウンロード処理完了のエンドポイントを追加 - /run/download_ctranslate2_weight - /run/downloaded_whisper_weight
This commit is contained in:
@@ -60,30 +60,30 @@ def checkCTranslate2Weight(path, weight_type="Small"):
|
||||
already_downloaded = True
|
||||
return already_downloaded
|
||||
|
||||
def downloadCTranslate2Weight(root, weight_type="Small", callbackFunc=None):
|
||||
def downloadCTranslate2Weight(root, weight_type="Small", callback=None, end_callback=None):
|
||||
url = ctranslate2_weights[weight_type]["url"]
|
||||
filename = "weight.zip"
|
||||
path = os_path.join(root, "weights", "ctranslate2")
|
||||
os_makedirs(path, exist_ok=True)
|
||||
|
||||
if checkCTranslate2Weight(path, weight_type):
|
||||
callbackFunc(1)
|
||||
return
|
||||
if checkCTranslate2Weight(path, weight_type) is False:
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp_path:
|
||||
res = requests_get(url, stream=True)
|
||||
file_size = int(res.headers.get('content-length', 0))
|
||||
total_chunk = 0
|
||||
with open(os_path.join(tmp_path, filename), 'wb') as file:
|
||||
for chunk in res.iter_content(chunk_size=1024*2000):
|
||||
file.write(chunk)
|
||||
if isinstance(callback, Callable):
|
||||
total_chunk += len(chunk)
|
||||
callback(total_chunk/file_size)
|
||||
printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}")
|
||||
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp_path:
|
||||
res = requests_get(url, stream=True)
|
||||
file_size = int(res.headers.get('content-length', 0))
|
||||
total_chunk = 0
|
||||
with open(os_path.join(tmp_path, filename), 'wb') as file:
|
||||
for chunk in res.iter_content(chunk_size=1024*2000):
|
||||
file.write(chunk)
|
||||
if isinstance(callbackFunc, Callable):
|
||||
total_chunk += len(chunk)
|
||||
callbackFunc(total_chunk/file_size)
|
||||
printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}")
|
||||
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
||||
zf.extractall(path)
|
||||
except Exception as e:
|
||||
printLog("warning:downloadCTranslate2Weight()", e)
|
||||
|
||||
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
||||
zf.extractall(path)
|
||||
except Exception as e:
|
||||
printLog("warning:downloadCTranslate2Weight()", e)
|
||||
if isinstance(end_callback, Callable):
|
||||
end_callback()
|
||||
Reference in New Issue
Block a user