👍️[Update] Controller : 起動時にモデルのweightファイルをダウンロードするように実装
This commit is contained in:
@@ -1292,7 +1292,7 @@ def getListInputDevice(*args, **kwargs) -> dict:
|
|||||||
def getListOutputDevice(*args, **kwargs) -> dict:
|
def getListOutputDevice(*args, **kwargs) -> dict:
|
||||||
return {"status":200, "result": model.getListOutputDevice()}
|
return {"status":200, "result": model.getListOutputDevice()}
|
||||||
|
|
||||||
def init():
|
def init(endpoints:dict, *args, **kwargs) -> None:
|
||||||
print(json.dumps({"status":348, "log": "Start Initialization"}), flush=True)
|
print(json.dumps({"status":348, "log": "Start Initialization"}), flush=True)
|
||||||
print(json.dumps({"status":348, "log": "Start InitSetTranslateEngine"}), flush=True)
|
print(json.dumps({"status":348, "log": "Start InitSetTranslateEngine"}), flush=True)
|
||||||
initSetTranslateEngine()
|
initSetTranslateEngine()
|
||||||
@@ -1311,6 +1311,19 @@ def init():
|
|||||||
print(json.dumps({"status":348, "log": "Set Translation Engine"}), flush=True)
|
print(json.dumps({"status":348, "log": "Set Translation Engine"}), flush=True)
|
||||||
updateTranslationEngineAndEngineList()
|
updateTranslationEngineAndEngineList()
|
||||||
|
|
||||||
|
# check Downloaded CTranslate2 Model Weight
|
||||||
|
print(json.dumps({"status":348, "log": "Check Downloaded CTranslate2 Model Weight"}), flush=True)
|
||||||
|
if config.USE_TRANSLATION_FEATURE is True and model.checkCTranslatorCTranslate2ModelWeight() is False:
|
||||||
|
def callback(progress):
|
||||||
|
print(json.dumps({
|
||||||
|
"endpoint":endpoints["ctranslate2"],
|
||||||
|
"status":200,
|
||||||
|
"result":{
|
||||||
|
"progress":progress
|
||||||
|
}
|
||||||
|
}), flush=True)
|
||||||
|
model.downloadCTranslate2ModelWeight(callback)
|
||||||
|
|
||||||
# set Transcription Engine
|
# set Transcription Engine
|
||||||
print(json.dumps({"status":348, "log": "Set Transcription Engine"}), flush=True)
|
print(json.dumps({"status":348, "log": "Set Transcription Engine"}), flush=True)
|
||||||
if config.USE_WHISPER_FEATURE is True:
|
if config.USE_WHISPER_FEATURE is True:
|
||||||
@@ -1318,6 +1331,19 @@ def init():
|
|||||||
else:
|
else:
|
||||||
config.SELECTED_TRANSCRIPTION_ENGINE = "Google"
|
config.SELECTED_TRANSCRIPTION_ENGINE = "Google"
|
||||||
|
|
||||||
|
# check Downloaded Whisper Model Weight
|
||||||
|
print(json.dumps({"status":348, "log": "Check Downloaded Whisper Model Weight"}), flush=True)
|
||||||
|
if config.USE_WHISPER_FEATURE is True and model.checkTranscriptionWhisperModelWeight() is False:
|
||||||
|
def callback(progress):
|
||||||
|
print(json.dumps({
|
||||||
|
"endpoint":endpoints["whisper"],
|
||||||
|
"status":200,
|
||||||
|
"result":{
|
||||||
|
"progress":progress
|
||||||
|
}
|
||||||
|
}), flush=True)
|
||||||
|
model.downloadWhisperModelWeight(callback)
|
||||||
|
|
||||||
# set word filter
|
# set word filter
|
||||||
print(json.dumps({"status":348, "log": "Set Word Filter"}), flush=True)
|
print(json.dumps({"status":348, "log": "Set Word Filter"}), flush=True)
|
||||||
model.addKeywords()
|
model.addKeywords()
|
||||||
|
|||||||
@@ -326,14 +326,18 @@ def main():
|
|||||||
print(response, flush=True)
|
print(response, flush=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
print(json.dumps({"status":200, "endpoint": "/initialization/start", "result":True}), flush=True)
|
||||||
|
controller.init({
|
||||||
|
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"],
|
||||||
|
"whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"],
|
||||||
|
})
|
||||||
|
print(json.dumps({"status":200, "endpoint": "/initialization/completed", "result":True}), flush=True)
|
||||||
|
print(json.dumps({"status":348, "log": "Initialization from Python."}), flush=True)
|
||||||
|
|
||||||
process = "main"
|
process = "main"
|
||||||
match process:
|
match process:
|
||||||
case "main":
|
case "main":
|
||||||
try:
|
try:
|
||||||
print(json.dumps({"status":200, "endpoint": "/initialization/start", "result":True}), flush=True)
|
|
||||||
controller.init()
|
|
||||||
print(json.dumps({"status":200, "endpoint": "/initialization/completed", "result":True}), flush=True)
|
|
||||||
print(json.dumps({"status":348, "log": "Initialization from Python."}), flush=True)
|
|
||||||
while True:
|
while True:
|
||||||
main()
|
main()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -342,7 +346,6 @@ if __name__ == "__main__":
|
|||||||
traceback.print_exc(file=f)
|
traceback.print_exc(file=f)
|
||||||
|
|
||||||
case "test":
|
case "test":
|
||||||
controller.init()
|
|
||||||
response_data, status = handleControllerRequest("/controller/callback_download_ctranslate2_weight")
|
response_data, status = handleControllerRequest("/controller/callback_download_ctranslate2_weight")
|
||||||
response = {
|
response = {
|
||||||
"status": status,
|
"status": status,
|
||||||
@@ -360,7 +363,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
case "test_all":
|
case "test_all":
|
||||||
import time
|
import time
|
||||||
controller.init()
|
|
||||||
for endpoint, value in config_mapping.items():
|
for endpoint, value in config_mapping.items():
|
||||||
response_data, status = handleConfigRequest(endpoint)
|
response_data, status = handleConfigRequest(endpoint)
|
||||||
response = {
|
response = {
|
||||||
|
|||||||
Reference in New Issue
Block a user