👍️[Update] Model : Deviceの変更監視処理を変更

- デバイス監視処理実行時にデバイス選択を行うとアクセス干渉のために動作停止の可能性あり
This commit is contained in:
misyaguziya
2024-09-15 17:25:02 +09:00
parent 551bc424b8
commit 5deeb4da2d
3 changed files with 45 additions and 44 deletions

View File

@@ -241,11 +241,11 @@ action_mapping = {
"download":"/action/download_whisper_weight"
},
"/controller/callback_enable_mic_automatic_selection": {
"mic":"/controller/callback_set_mic_device",
"mic":"/controller/callback_set_mic_host",
"speaker":"/controller/callback_set_speaker_device",
},
"/controller/callback_enable_speaker_automatic_selection": {
"mic":"/controller/callback_set_mic_device",
"mic":"/controller/callback_set_mic_host",
"speaker":"/controller/callback_set_speaker_device",
}
}
@@ -267,12 +267,16 @@ def handleControllerRequest(endpoint, data=None):
status = 404
else:
action_endpoint = action_mapping.get(endpoint, None)
if action_endpoint is not None:
response = handler(data, Action(action_endpoint).transmit)
else:
response = handler(data)
status = response.get("status", None)
result = response.get("result", None)
try:
if action_endpoint is not None:
response = handler(data, Action(action_endpoint).transmit)
else:
response = handler(data)
status = response.get("status", None)
result = response.get("result", None)
except Exception as e:
result = str(e)
status = 500
return result, status
class Action:
@@ -280,9 +284,12 @@ class Action:
self.endpoints = endpoints
def transmit(self, key:str, data:dict) -> None:
status = data.get("status", None)
result = data.get("result", None)
printResponse(status, self.endpoints[key], result)
if key not in self.endpoints:
printLog("Invalid endpoint", key)
else:
status = data.get("status", None)
result = data.get("result", None)
printResponse(status, self.endpoints[key], result)
def main():
received_data = sys.stdin.readline().strip()
@@ -292,7 +299,7 @@ def main():
endpoint = received_data.get("endpoint", None)
data = received_data.get("data", None)
data = encodeBase64(data) if data is not None else None
printLog(endpoint, data)
printLog(endpoint, {"receive_data":data})
try:
match endpoint.split("/")[1]:
@@ -305,14 +312,14 @@ def main():
except Exception as e:
result = str(e)
status = 500
printLog(endpoint, {"send_data":result})
printResponse(status, endpoint, result)
if __name__ == "__main__":
controller.init({
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"],
"whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"],
"check_mic_device": action_mapping["/controller/callback_enable_mic_automatic_selection"]["mic"],
"check_speaker_device": action_mapping["/controller/callback_enable_speaker_automatic_selection"]["speaker"],
"download_ctranslate2": Action(action_mapping["/controller/callback_download_ctranslate2_weight"]).transmit,
"download_whisper": Action(action_mapping["/controller/callback_download_whisper_weight"]).transmit,
"update_selected_device": Action(action_mapping["/controller/callback_enable_mic_automatic_selection"]).transmit,
})
process = "main"
@@ -327,12 +334,11 @@ if __name__ == "__main__":
traceback.print_exc(file=f)
case "test":
endpoint = "/controller/callback_download_ctranslate2_weight"
result, status = handleControllerRequest(endpoint)
printResponse(status, endpoint, result)
endpoint = "/controller/callback_download_whisper_weight"
result, status = handleControllerRequest(endpoint)
printResponse(status, endpoint, result)
for _ in range(100):
time.sleep(0.5)
endpoint = "/controller/list_mic_host"
result, status = handleControllerRequest(endpoint)
printResponse(status, endpoint, result)
case "test_all":
import time