From ee5c4c05ce0c5c9aa9a5aa6279ba3605cd0eede1 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Fri, 2 Feb 2024 18:08:18 +0900 Subject: [PATCH] =?UTF-8?q?[WIP/TEST]=20UI:=20=E6=A9=9F=E8=83=BD=E3=81=A8?= =?UTF-8?q?=E8=A6=8B=E3=81=9F=E7=9B=AE=E3=82=92=E7=B9=8B=E3=81=8E=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82=E8=A8=AD=E5=AE=9A=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E3=81=8B=E3=82=89=E3=81=84=E3=81=98=E3=82=8C=E3=81=BE=E3=81=99?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller.py | 33 ++++++++++++ locales/en.yml | 16 ++++++ view.py | 52 +++++++++++++++++++ .../createSideMenuAndSettingsBoxContainers.py | 6 ++- .../setting_box_transcription/__init__.py | 3 +- .../createSettingBox_InternalModel.py | 37 +++++++++++++ 6 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_InternalModel.py diff --git a/controller.py b/controller.py index 9d44b491..724d2cf3 100644 --- a/controller.py +++ b/controller.py @@ -767,6 +767,35 @@ def callbackSetSpeakerMaxPhrases(value): except Exception: view.showErrorMessage_SpeakerMaxPhrases() +# Transcription (Internal AI Model) +def callbackSetUserWhisperFeature(value): + print("callbackSetUserWhisperFeature", value) + config.USE_WHISPER_FEATURE = value + if config.USE_WHISPER_FEATURE is True: + view.openWhisperWeightTypeWidget() + else: + view.closeWhisperWeightTypeWidget() + +def callbackSetWhisperWeightType(value): + print("callbackSetWhisperWeightType", value) + config.WHISPER_WEIGHT_TYPE = str(value) + view.updateSelectedWhisperWeightType(config.WHISPER_WEIGHT_TYPE) + # view.setWidgetsStatus_changeWeightType_Pending() + # if model.checkCTranslatorCTranslate2ModelWeight(): + # config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False + # def callback(): + # model.changeTranslatorCTranslate2Model() + # view.useTranslationFeatureProcess("Normal") + # view.setWidgetsStatus_changeWeightType_Done() + # th_callback = Thread(target=callback) + # th_callback.daemon = True + # th_callback.start() + # else: + # config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True + # view.useTranslationFeatureProcess("Restart") + # view.setWidgetsStatus_changeWeightType_Done() + # view.showRestartButtonIfRequired() + # Others Tab def callbackSetEnableAutoClearMessageBox(value): @@ -993,6 +1022,10 @@ def createMainWindow(splash): "callback_set_speaker_phrase_timeout": callbackSetSpeakerPhraseTimeout, "callback_set_speaker_max_phrases": callbackSetSpeakerMaxPhrases, + # Transcription Tab (Internal AI Model) + "callback_set_use_whisper_feature": callbackSetUserWhisperFeature, + "callback_set_whisper_weight_type": callbackSetWhisperWeightType, + # Others Tab "callback_set_enable_auto_clear_chatbox": callbackSetEnableAutoClearMessageBox, "callback_set_send_only_translated_messages": callbackSetEnableSendOnlyTranslatedMessages, diff --git a/locales/en.yml b/locales/en.yml index 2806ea91..f68aa32c 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -79,6 +79,7 @@ config_window: transcription: Transcription transcription_mic: Mic transcription_speaker: Speaker + transcription_internal_model: Internal Model others: Others others_send_message_formats: Message Formats (Send) others_received_message_formats: Message Formats (Received) @@ -125,6 +126,21 @@ config_window: small: "Basic model (%{capacity})" large: "High accuracy model (%{capacity})" + use_whisper_feature: + label: Use Whisper Feature + desc: Description + + whisper_weight_type: + label: Select Whisper Model + desc: Description + tiny: "tiny model (%{capacity})" + base: "base model (%{capacity})" + small: "small model (%{capacity})" + medium: "medium model (%{capacity})" + large_v1: "large_v1 model (%{capacity})" + large_v2: "large_v2 model (%{capacity})" + large_v3: "large_v3 model (%{capacity})" + deepl_auth_key: label: DeepL Auth Key desc: Please select %{translator} on the main screen with DeepL_API when using. ※Some languages may not be supported. diff --git a/view.py b/view.py index cf90dcfa..6f7a6d7e 100644 --- a/view.py +++ b/view.py @@ -211,6 +211,7 @@ class View(): VAR_SIDE_MENU_LABEL_TRANSCRIPTION=StringVar(value=i18n.t("config_window.side_menu_labels.transcription")), VAR_SECOND_TITLE_TRANSCRIPTION_MIC=StringVar(value=i18n.t("config_window.side_menu_labels.transcription_mic")), VAR_SECOND_TITLE_TRANSCRIPTION_SPEAKER=StringVar(value=i18n.t("config_window.side_menu_labels.transcription_speaker")), + VAR_SECOND_TITLE_TRANSCRIPTION_INTERNAL_MODEL=StringVar(value=i18n.t("config_window.side_menu_labels.transcription_internal_model")), VAR_SIDE_MENU_LABEL_OTHERS=StringVar(value=i18n.t("config_window.side_menu_labels.others")), VAR_SIDE_MENU_LABEL_ADVANCED_SETTINGS=StringVar(value=i18n.t("config_window.side_menu_labels.advanced_settings")), @@ -381,6 +382,19 @@ class View(): CALLBACK_FOCUS_OUT_SPEAKER_MAX_PHRASES=self.callbackBindFocusOut_SpeakerMaxPhrases, + # Transcription Tab (Whisper Internal AI Model) + VAR_LABEL_USE_WHISPER_FEATURE=StringVar(value=i18n.t("config_window.use_whisper_feature.label")), + VAR_DESC_USE_WHISPER_FEATURE=StringVar(value=i18n.t("config_window.use_whisper_feature.desc")), + CALLBACK_SET_USE_WHISPER_FEATURE=None, + VAR_USE_WHISPER_FEATURE=BooleanVar(value=config.USE_WHISPER_FEATURE), + + VAR_LABEL_WHISPER_WEIGHT_TYPE=StringVar(value=i18n.t("config_window.whisper_weight_type.label")), + VAR_DESC_WHISPER_WEIGHT_TYPE=StringVar(value=i18n.t("config_window.whisper_weight_type.desc")), + DICT_WHISPER_WEIGHT_TYPE=self.getSelectableWhisperWeightTypeDict(), + CALLBACK_SET_WHISPER_WEIGHT_TYPE=None, + VAR_WHISPER_WEIGHT_TYPE=StringVar(value=self.getSelectableWhisperWeightTypeDict()[config.WHISPER_WEIGHT_TYPE]), + + # Others Tab VAR_LABEL_ENABLE_AUTO_CLEAR_MESSAGE_BOX=StringVar(value=i18n.t("config_window.auto_clear_the_message_box.label")), VAR_DESC_ENABLE_AUTO_CLEAR_MESSAGE_BOX=None, @@ -624,6 +638,11 @@ class View(): self.view_variable.CALLBACK_SET_SPEAKER_PHRASE_TIMEOUT = config_window_registers.get("callback_set_speaker_phrase_timeout", None) self.view_variable.CALLBACK_SET_SPEAKER_MAX_PHRASES = config_window_registers.get("callback_set_speaker_max_phrases", None) + # Transcription Tab (Internal AI Model) + self.view_variable.CALLBACK_SET_USE_WHISPER_FEATURE = config_window_registers.get("callback_set_use_whisper_feature", None) + self.view_variable.CALLBACK_SET_WHISPER_WEIGHT_TYPE = config_window_registers.get("callback_set_whisper_weight_type", None) + + # Others Tab self.view_variable.CALLBACK_SET_ENABLE_AUTO_CLEAR_MESSAGE_BOX = config_window_registers.get("callback_set_enable_auto_clear_chatbox", None) self.view_variable.CALLBACK_SET_ENABLE_SEND_ONLY_TRANSLATED_MESSAGES = config_window_registers.get("callback_set_send_only_translated_messages", None) @@ -678,6 +697,11 @@ class View(): ) self.replaceMicThresholdCheckButton_Disabled() + if config.USE_WHISPER_FEATURE is True: + self.openWhisperWeightTypeWidget() + else: + self.closeWhisperWeightTypeWidget() + if config.ENABLE_SPEAKER2CHATBOX is False: vrct_gui._changeConfigWindowWidgetsStatus( status="disabled", @@ -919,6 +943,17 @@ class View(): vrct_gui.update() vrct_gui.config_window.lift() + @staticmethod + def getSelectableWhisperWeightTypeDict(): + return { + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT["tiny"]: i18n.t("config_window.whisper_weight_type.tiny", capacity="t"), + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT["base"]: i18n.t("config_window.whisper_weight_type.base", capacity="b"), + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT["small"]: i18n.t("config_window.whisper_weight_type.small", capacity="s"), + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT["medium"]: i18n.t("config_window.whisper_weight_type.medium", capacity="m"), + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT["large-v1"]: i18n.t("config_window.whisper_weight_type.large_v1", capacity="l_v1"), + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT["large-v2"]: i18n.t("config_window.whisper_weight_type.large_v2", capacity="l_v2"), + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT["large-v3"]: i18n.t("config_window.whisper_weight_type.large_v3", capacity="l_v3"), + } # Open Webpage Functions def openWebPage_Booth(self): @@ -1082,6 +1117,23 @@ class View(): vrct_gui.config_window.sb__ctranslate2_weight_type.grid_remove() + def openWhisperWeightTypeWidget(self): + vrct_gui.config_window.sb__use_whisper_feature.grid() + vrct_gui.config_window.sb__whisper_weight_type.grid() + + def closeWhisperWeightTypeWidget(self): + vrct_gui.config_window.sb__use_whisper_feature.grid() + vrct_gui.config_window.sb__whisper_weight_type.grid_remove() + + + def updateSelectedWhisperWeightType(self, selected_weight_type:str): + self.view_variable.VAR_WHISPER_WEIGHT_TYPE.set(self.getSelectableWhisperWeightTypeDict()[selected_weight_type]) + + def setLatestCTranslate2WeightType(self): + selected_weight_type = self.getSelectableWhisperWeightTypeDict()[config.WHISPER_WEIGHT_TYPE] + self.view_variable.VAR_WHISPER_WEIGHT_TYPE.set(selected_weight_type) + + def openMicEnergyThresholdWidget(self): self.view_variable.VAR_LABEL_MIC_DYNAMIC_ENERGY_THRESHOLD.set(i18n.t("config_window.mic_dynamic_energy_threshold.label_for_manual")) self.view_variable.VAR_DESC_MIC_DYNAMIC_ENERGY_THRESHOLD.set(i18n.t("config_window.mic_dynamic_energy_threshold.desc_for_manual")) diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py index 30af50de..49272afc 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py @@ -7,7 +7,7 @@ from ._createSettingBoxContainer import _createSettingBoxContainer from .setting_box_containers.setting_box_appearance import createSettingBox_Appearance -from .setting_box_containers.setting_box_transcription import createSettingBox_Mic, createSettingBox_Speaker +from .setting_box_containers.setting_box_transcription import createSettingBox_Mic, createSettingBox_Speaker, createSettingBox_InternalModel from .setting_box_containers.setting_box_others import createSettingBox_Others, createSettingBox_Others_SendMessageFormats, createSettingBox_Others_ReceivedMessageFormats, createSettingBox_Others_Additional from .setting_box_containers.setting_box_advanced_settings import createSettingBox_AdvancedSettings from .setting_box_containers.setting_box_translation import createSettingBox_Translation @@ -94,6 +94,10 @@ def createSideMenuAndSettingsBoxContainers(config_window, settings, view_variabl "var_section_title": view_variable.VAR_SECOND_TITLE_TRANSCRIPTION_SPEAKER, "setting_box": createSettingBox_Speaker }, + { + "var_section_title": view_variable.VAR_SECOND_TITLE_TRANSCRIPTION_INTERNAL_MODEL, + "setting_box": createSettingBox_InternalModel + }, ] }, }, diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/__init__.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/__init__.py index 5383094e..b06ff822 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/__init__.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/__init__.py @@ -1,2 +1,3 @@ from .createSettingBox_Mic import createSettingBox_Mic -from .createSettingBox_Speaker import createSettingBox_Speaker \ No newline at end of file +from .createSettingBox_Speaker import createSettingBox_Speaker +from .createSettingBox_InternalModel import createSettingBox_InternalModel \ No newline at end of file diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_InternalModel.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_InternalModel.py new file mode 100644 index 00000000..0a6b3e69 --- /dev/null +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_InternalModel.py @@ -0,0 +1,37 @@ +from utils import callFunctionIfCallable + +from .._SettingBoxGenerator import _SettingBoxGenerator + +def createSettingBox_InternalModel(setting_box_wrapper, config_window, settings, view_variable): + sbg = _SettingBoxGenerator(setting_box_wrapper, config_window, settings, view_variable) + createSettingBoxSwitch = sbg.createSettingBoxSwitch + createSettingBoxDropdownMenu = sbg.createSettingBoxDropdownMenu + + def switchUseWhisperFeatureCallback(switch_widget): + callFunctionIfCallable(view_variable.CALLBACK_SET_USE_WHISPER_FEATURE, switch_widget.get()) + + def optionmenuWhisperWeightTypeCallback(value): + callFunctionIfCallable(view_variable.CALLBACK_SET_WHISPER_WEIGHT_TYPE, value) + + + row=0 + config_window.sb__use_whisper_feature = createSettingBoxSwitch( + for_var_label_text=view_variable.VAR_LABEL_USE_WHISPER_FEATURE, + for_var_desc_text=view_variable.VAR_DESC_USE_WHISPER_FEATURE, + switch_attr_name="sb__switch_use_whisper_feature", + command=lambda: switchUseWhisperFeatureCallback(config_window.sb__switch_use_whisper_feature), + variable=view_variable.VAR_USE_WHISPER_FEATURE + ) + config_window.sb__use_whisper_feature.grid(row=row, pady=0) + row+=1 + + config_window.sb__whisper_weight_type = createSettingBoxDropdownMenu( + for_var_label_text=view_variable.VAR_LABEL_WHISPER_WEIGHT_TYPE, + for_var_desc_text=view_variable.VAR_DESC_WHISPER_WEIGHT_TYPE, + optionmenu_attr_name="sb__optionmenu_whisper_weight_type", + dropdown_menu_values=view_variable.DICT_WHISPER_WEIGHT_TYPE, + command=lambda value: optionmenuWhisperWeightTypeCallback(value), + variable=view_variable.VAR_WHISPER_WEIGHT_TYPE, + ) + config_window.sb__whisper_weight_type.grid(row=row, pady=0) + row+=1 \ No newline at end of file