Merge branch 'send_message' into for_webui
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
@if not "%~0"=="%~dp0.\%~nx0" start /min cmd /c,"%~dp0.\%~nx0" %* & goto :eof
|
|
||||||
|
|
||||||
set name=%1
|
|
||||||
set local_path=%~dp0
|
|
||||||
|
|
||||||
taskkill /im %name% /F
|
|
||||||
ping -n 2 127.0.0.1 > nul
|
|
||||||
START "" "%local_path%%name%"
|
|
||||||
del /f "%~dp0%~nx0"
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
@if not "%~0"=="%~dp0.\%~nx0" start /min cmd /c,"%~dp0.\%~nx0" %* & goto :eof
|
|
||||||
|
|
||||||
set exe_name=%1
|
|
||||||
set folder_name=%2
|
|
||||||
set folder_tmp=%3
|
|
||||||
set restart=%4
|
|
||||||
set local_path=%~dp0
|
|
||||||
|
|
||||||
taskkill /im %exe_name% /F
|
|
||||||
ping -n 2 127.0.0.1 > nul
|
|
||||||
del /f "%local_path%%exe_name%"
|
|
||||||
rmdir /s /q "%local_path%%folder_name%"
|
|
||||||
xcopy "%local_path%%folder_tmp%" "%local_path%" /E /I
|
|
||||||
rmdir /s /q "%local_path%%folder_tmp%"
|
|
||||||
|
|
||||||
if %restart% == True (
|
|
||||||
START "" "%local_path%%exe_name%"
|
|
||||||
)
|
|
||||||
|
|
||||||
del /f "%~dp0%~nx0"
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"setup-python": "install.bat",
|
"setup-python": "install.bat",
|
||||||
"build-python": "pyinstaller -F src-python/webui_mainloop.py --add-data ./fonts;fonts/ --add-data ./batch;batch/ --add-data .venv/Lib/site-packages/zeroconf;zeroconf/ --add-data .venv/Lib/site-packages/openvr;openvr/ --distpath src-tauri/bin --exclude-module pandas --exclude-module matplotlib --exclude-module PyQt5 --clean -n backend-x86_64-pc-windows-msvc",
|
"build-python": "pyinstaller -F src-python/webui_mainloop.py --add-data ./fonts;fonts/ --add-data .venv/Lib/site-packages/zeroconf;zeroconf/ --add-data .venv/Lib/site-packages/openvr;openvr/ --distpath src-tauri/bin --exclude-module pandas --exclude-module matplotlib --exclude-module PyQt5 --clean -n backend-x86_64-pc-windows-msvc --icon=./src-ui/assets/chato_icon_fill.png",
|
||||||
"vite": "vite",
|
"vite": "vite",
|
||||||
"vite-build": "vite build",
|
"vite-build": "vite build",
|
||||||
"vite-preview": "vite preview",
|
"vite-preview": "vite preview",
|
||||||
|
|||||||
@@ -5,11 +5,17 @@ from subprocess import Popen
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from config import config
|
from config import config
|
||||||
from model import model
|
from model import model
|
||||||
# from view import view
|
from utils import getKeyByValue, isUniqueStrings
|
||||||
from utils import getKeyByValue, isUniqueStrings, strPctToInt
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
# Common
|
# Common
|
||||||
|
def encodeUtf8(data:str) -> dict:
|
||||||
|
data = {i: byte for i, byte in enumerate(data.encode('UTF-8'))}
|
||||||
|
return data
|
||||||
|
|
||||||
|
def decodeUtf8(data:dict) -> str:
|
||||||
|
data = bytes(data.values()).decode("UTF-8")
|
||||||
|
return data
|
||||||
|
|
||||||
class DownloadSoftwareProgressBar:
|
class DownloadSoftwareProgressBar:
|
||||||
def __init__(self, action):
|
def __init__(self, action):
|
||||||
self.action = action
|
self.action = action
|
||||||
@@ -303,7 +309,9 @@ class ChatMessage:
|
|||||||
def __init__(self, action:Callable[[dict], None]) -> None:
|
def __init__(self, action:Callable[[dict], None]) -> None:
|
||||||
self.action = action
|
self.action = action
|
||||||
|
|
||||||
def send(self, message):
|
def send(self, data):
|
||||||
|
id = data["id"]
|
||||||
|
message = decodeUtf8(data["message"])
|
||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
addSentMessageLog(message)
|
addSentMessageLog(message)
|
||||||
translation = ""
|
translation = ""
|
||||||
@@ -343,11 +351,13 @@ class ChatMessage:
|
|||||||
translation = f" ({translation})"
|
translation = f" ({translation})"
|
||||||
model.logger.info(f"[SENT] {message}{translation}")
|
model.logger.info(f"[SENT] {message}{translation}")
|
||||||
|
|
||||||
|
message = encodeUtf8(message)
|
||||||
|
translation = encodeUtf8(translation)
|
||||||
return {"status":200,
|
return {"status":200,
|
||||||
"result":{
|
"result":{
|
||||||
|
"id":id,
|
||||||
"message":message,
|
"message":message,
|
||||||
"translation":translation,
|
"translation":translation,
|
||||||
"clear":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1292,7 +1302,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 +1321,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 +1341,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()
|
||||||
@@ -1336,4 +1372,5 @@ def init():
|
|||||||
print(json.dumps({"status":348, "log": "Init OSC Receive"}), flush=True)
|
print(json.dumps({"status":348, "log": "Init OSC Receive"}), flush=True)
|
||||||
model.startReceiveOSC()
|
model.startReceiveOSC()
|
||||||
if config.ENABLE_VRC_MIC_MUTE_SYNC is True:
|
if config.ENABLE_VRC_MIC_MUTE_SYNC is True:
|
||||||
model.startCheckMuteSelfStatus()
|
model.startCheckMuteSelfStatus()
|
||||||
|
print(json.dumps({"status":348, "log": "End Initialization"}), flush=True)
|
||||||
@@ -326,14 +326,15 @@ def main():
|
|||||||
print(response, flush=True)
|
print(response, flush=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
controller.init({
|
||||||
|
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"],
|
||||||
|
"whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"],
|
||||||
|
})
|
||||||
|
|
||||||
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 +343,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 +360,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 = {
|
||||||
|
|||||||
@@ -82,12 +82,4 @@ export const useMainFunction = () => {
|
|||||||
},
|
},
|
||||||
currentForegroundStatus: currentForegroundStatus,
|
currentForegroundStatus: currentForegroundStatus,
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const asyncTestFunction = (...args) => {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve(...args);
|
|
||||||
}, 3000);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
@@ -7,11 +7,16 @@ import { useStdoutToPython } from "./useStdoutToPython";
|
|||||||
export const useMessage = () => {
|
export const useMessage = () => {
|
||||||
const { currentMessageLogsStatus, addMessageLogsStatus, updateMessageLogsStatus } = useMessageLogsStatus();
|
const { currentMessageLogsStatus, addMessageLogsStatus, updateMessageLogsStatus } = useMessageLogsStatus();
|
||||||
const { asyncStdoutToPython } = useStdoutToPython();
|
const { asyncStdoutToPython } = useStdoutToPython();
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sendMessage: (message) => {
|
sendMessage: (message) => {
|
||||||
asyncStdoutToPython({id: "send_message", data: message});
|
|
||||||
const uuid = crypto.randomUUID();
|
const uuid = crypto.randomUUID();
|
||||||
|
const send_message_object = {
|
||||||
|
id: uuid,
|
||||||
|
message: encoder.encode(message),
|
||||||
|
};
|
||||||
|
asyncStdoutToPython("/controller/callback_messagebox_press_key_enter", send_message_object);
|
||||||
|
|
||||||
addMessageLogsStatus({
|
addMessageLogsStatus({
|
||||||
id: uuid,
|
id: uuid,
|
||||||
@@ -20,26 +25,16 @@ export const useMessage = () => {
|
|||||||
created_at: generateTimeData(),
|
created_at: generateTimeData(),
|
||||||
messages: {
|
messages: {
|
||||||
original: message,
|
original: message,
|
||||||
translated: [
|
translated: [],
|
||||||
message,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
const updateItemById = (id) => (prevItems) => {
|
|
||||||
return prevItems.map(item => {
|
|
||||||
if (item.id === id) {
|
|
||||||
item.status = "ok";
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
updateMessageLogsStatus(updateItemById(uuid));
|
|
||||||
}, 3000);
|
|
||||||
},
|
},
|
||||||
currentMessageLogsStatus: currentMessageLogsStatus,
|
currentMessageLogsStatus: currentMessageLogsStatus,
|
||||||
|
|
||||||
|
updateSentMessageLog: (payload) => {
|
||||||
|
const data = payload.data;
|
||||||
|
updateMessageLogsStatus(updateItemById(data.id));
|
||||||
|
},
|
||||||
addSentMessageLog: (payload) => {
|
addSentMessageLog: (payload) => {
|
||||||
const data = payload.data;
|
const data = payload.data;
|
||||||
const message_object = generateMessageObject(data, "sent");
|
const message_object = generateMessageObject(data, "sent");
|
||||||
@@ -72,4 +67,14 @@ const generateMessageObject = (data, category) => {
|
|||||||
translated: [],
|
translated: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const updateItemById = (id) => (prev_items) => {
|
||||||
|
return prev_items.map(item => {
|
||||||
|
if (item.id === id) {
|
||||||
|
item.status = "ok";
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
@@ -9,7 +9,11 @@ export const useReceiveRoutes = () => {
|
|||||||
updateTranscriptionReceiveStatus,
|
updateTranscriptionReceiveStatus,
|
||||||
} = useMainFunction();
|
} = useMainFunction();
|
||||||
|
|
||||||
const { addSentMessageLog, addReceivedMessageLog } = useMessage();
|
const {
|
||||||
|
updateSentMessageLog,
|
||||||
|
addSentMessageLog,
|
||||||
|
addReceivedMessageLog,
|
||||||
|
} = useMessage();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
updateSoftwareVersion,
|
updateSoftwareVersion,
|
||||||
@@ -25,6 +29,7 @@ export const useReceiveRoutes = () => {
|
|||||||
|
|
||||||
"/config/version": updateSoftwareVersion,
|
"/config/version": updateSoftwareVersion,
|
||||||
|
|
||||||
|
"/controller/callback_messagebox_press_key_enter": updateSentMessageLog,
|
||||||
"/action/transcription_send_mic_message": addSentMessageLog,
|
"/action/transcription_send_mic_message": addSentMessageLog,
|
||||||
"/action/transcription_receive_speaker_message": addReceivedMessageLog
|
"/action/transcription_receive_speaker_message": addReceivedMessageLog
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user