👍️[Update] Model : モデルのダウンロード処理をスレッドで進行するように変更
This commit is contained in:
@@ -40,6 +40,7 @@ def downloadFile(url, path, func=None):
|
|||||||
if isinstance(func, Callable):
|
if isinstance(func, Callable):
|
||||||
total_chunk += len(chunk)
|
total_chunk += len(chunk)
|
||||||
func(total_chunk/file_size)
|
func(total_chunk/file_size)
|
||||||
|
printLog(f"Downloading Whisper Model: {total_chunk/file_size:.0%}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printLog("warning:downloadFile()", e)
|
printLog("warning:downloadFile()", e)
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ def downloadCTranslate2Weight(root, weight_type="Small", callbackFunc=None):
|
|||||||
if isinstance(callbackFunc, Callable):
|
if isinstance(callbackFunc, Callable):
|
||||||
total_chunk += len(chunk)
|
total_chunk += len(chunk)
|
||||||
callbackFunc(total_chunk/file_size)
|
callbackFunc(total_chunk/file_size)
|
||||||
printLog(f"Downloading {filename}: {total_chunk/file_size:.0%}")
|
printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}")
|
||||||
|
|
||||||
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
||||||
zf.extractall(path)
|
zf.extractall(path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printLog("error:downloadCTranslate2Weight()", e)
|
printLog("warning:downloadCTranslate2Weight()", e)
|
||||||
@@ -81,7 +81,7 @@ def printLog(log:str, data:Any=None) -> None:
|
|||||||
response = {
|
response = {
|
||||||
"status": 348,
|
"status": 348,
|
||||||
"log": log,
|
"log": log,
|
||||||
"data": data,
|
"data": str(data),
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('process.log', 'a', encoding="utf-8") as f:
|
with open('process.log', 'a', encoding="utf-8") as f:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
from typing import Callable, Union
|
from typing import Callable, Union
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
@@ -701,10 +700,15 @@ class DownloadCTranslate2ProgressBar:
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def startThreadingDownloadCtranslate2Weight(callback:Callable[[float], None]) -> None:
|
||||||
|
th_download = Thread(target=model.downloadCTranslate2ModelWeight, args=(callback,))
|
||||||
|
th_download.daemon = True
|
||||||
|
th_download.start()
|
||||||
|
|
||||||
def callbackDownloadCtranslate2Weight(data, action, *args, **kwargs) -> dict:
|
def callbackDownloadCtranslate2Weight(data, action, *args, **kwargs) -> dict:
|
||||||
printLog("Download CTranslate2 Weight")
|
printLog("Download CTranslate2 Weight")
|
||||||
download = DownloadCTranslate2ProgressBar(action)
|
download = DownloadCTranslate2ProgressBar(action)
|
||||||
model.downloadCTranslate2ModelWeight(download.set)
|
startThreadingDownloadCtranslate2Weight(download.set)
|
||||||
return {"status":200}
|
return {"status":200}
|
||||||
|
|
||||||
def callbackSetDeeplAuthKey(data, *args, **kwargs) -> dict:
|
def callbackSetDeeplAuthKey(data, *args, **kwargs) -> dict:
|
||||||
@@ -1034,10 +1038,15 @@ class DownloadWhisperProgressBar:
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def startThreadingDownloadWhisperWeight(callback:Callable[[float], None]) -> None:
|
||||||
|
th_download = Thread(target=model.downloadWhisperModelWeight, args=(callback,))
|
||||||
|
th_download.daemon = True
|
||||||
|
th_download.start()
|
||||||
|
|
||||||
def callbackDownloadWhisperWeight(data, action, *args, **kwargs) -> dict:
|
def callbackDownloadWhisperWeight(data, action, *args, **kwargs) -> dict:
|
||||||
printLog("Download Whisper Weight")
|
printLog("Download Whisper Weight")
|
||||||
download = DownloadCTranslate2ProgressBar(action)
|
download = DownloadWhisperProgressBar(action)
|
||||||
model.downloadWhisperModelWeight(download.set)
|
startThreadingDownloadWhisperWeight(download.set)
|
||||||
return {"status":200}
|
return {"status":200}
|
||||||
|
|
||||||
# VR Tab
|
# VR Tab
|
||||||
@@ -1283,8 +1292,7 @@ def init(endpoints:dict, *args, **kwargs) -> None:
|
|||||||
if config.USE_TRANSLATION_FEATURE is True and model.checkCTranslatorCTranslate2ModelWeight() is False:
|
if config.USE_TRANSLATION_FEATURE is True and model.checkCTranslatorCTranslate2ModelWeight() is False:
|
||||||
def callback(progress):
|
def callback(progress):
|
||||||
printResponse(200, endpoints["ctranslate2"], {"progress":progress})
|
printResponse(200, endpoints["ctranslate2"], {"progress":progress})
|
||||||
printLog("Download CTranslate2 Model Weight")
|
startThreadingDownloadCtranslate2Weight(callback)
|
||||||
model.downloadCTranslate2ModelWeight(callback)
|
|
||||||
|
|
||||||
# set Transcription Engine
|
# set Transcription Engine
|
||||||
printLog("Set Transcription Engine")
|
printLog("Set Transcription Engine")
|
||||||
@@ -1298,7 +1306,7 @@ def init(endpoints:dict, *args, **kwargs) -> None:
|
|||||||
if config.USE_WHISPER_FEATURE is True and model.checkTranscriptionWhisperModelWeight() is False:
|
if config.USE_WHISPER_FEATURE is True and model.checkTranscriptionWhisperModelWeight() is False:
|
||||||
def callback(progress):
|
def callback(progress):
|
||||||
printResponse(200, endpoints["whisper"], {"progress":progress})
|
printResponse(200, endpoints["whisper"], {"progress":progress})
|
||||||
model.downloadWhisperModelWeight(callback)
|
startThreadingDownloadWhisperWeight(callback)
|
||||||
|
|
||||||
# set word filter
|
# set word filter
|
||||||
printLog("Set Word Filter")
|
printLog("Set Word Filter")
|
||||||
|
|||||||
@@ -297,8 +297,8 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
controller.init({
|
controller.init({
|
||||||
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"],
|
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"],
|
||||||
"whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"],
|
"whisper": action_mapping["/controller/callback_download_whisper_weight"],
|
||||||
})
|
})
|
||||||
|
|
||||||
process = "main"
|
process = "main"
|
||||||
|
|||||||
Reference in New Issue
Block a user