👍️[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:
misyaguziya
2024-10-29 22:58:18 +09:00
parent 134ef373af
commit 7fd3fad3ea
6 changed files with 228 additions and 116 deletions

View File

@@ -63,17 +63,16 @@ def checkWhisperWeight(root, weight_type):
pass
return result
def downloadWhisperWeight(root, weight_type, callbackFunc):
def downloadWhisperWeight(root, weight_type, callback=None, end_callback=None):
path = os_path.join(root, "weights", "whisper", weight_type)
os_makedirs(path, exist_ok=True)
if checkWhisperWeight(root, weight_type) is True:
callbackFunc(1)
return
for filename in _FILENAMES:
file_path = os_path.join(path, filename)
url = huggingface_hub.hf_hub_url(_MODELS[weight_type], filename)
downloadFile(url, file_path, func=callbackFunc)
if checkWhisperWeight(root, weight_type) is False:
for filename in _FILENAMES:
file_path = os_path.join(path, filename)
url = huggingface_hub.hf_hub_url(_MODELS[weight_type], filename)
downloadFile(url, file_path, func=callback)
if isinstance(end_callback, Callable):
end_callback()
def getWhisperModel(root, weight_type, device="cpu", device_index=0):
path = os_path.join(root, "weights", "whisper", weight_type)
@@ -93,10 +92,14 @@ if __name__ == "__main__":
print(value)
pass
downloadWhisperWeight("./", "tiny", callback)
downloadWhisperWeight("./", "base", callback)
downloadWhisperWeight("./", "small", callback)
downloadWhisperWeight("./", "medium", callback)
downloadWhisperWeight("./", "large-v1", callback)
downloadWhisperWeight("./", "large-v2", callback)
downloadWhisperWeight("./", "large-v3", callback)
def end_callback():
print("end")
pass
downloadWhisperWeight("./", "tiny", callback, end_callback)
downloadWhisperWeight("./", "base", callback, end_callback)
downloadWhisperWeight("./", "small", callback, end_callback)
downloadWhisperWeight("./", "medium", callback, end_callback)
downloadWhisperWeight("./", "large-v1", callback, end_callback)
downloadWhisperWeight("./", "large-v2", callback, end_callback)
downloadWhisperWeight("./", "large-v3", callback, end_callback)