[Update] Config Page: Translation Tab. Add Internal Translation Weight Type Selector. Downloadable.

This commit is contained in:
Sakamoto Shiina
2024-11-12 13:02:05 +09:00
parent 43b061b007
commit 36c53c49a2
17 changed files with 365 additions and 139 deletions

View File

@@ -31,7 +31,9 @@ export { useSpeakerRecordTimeout } from "./transcription/useSpeakerRecordTimeout
export { useSpeakerPhraseTimeout } from "./transcription/useSpeakerPhraseTimeout";
export { useSpeakerMaxWords } from "./transcription/useSpeakerMaxWords";
export { useCTranslate2WeightTypeStatus } from "./translation/useCTranslate2WeightTypeStatus";
export { useDeepLAuthKey } from "./translation/useDeepLAuthKey";
export { useSelectedCTranslate2WeightType } from "./translation/useSelectedCTranslate2WeightType";
export { useIsEnabledOverlaySmallLog } from "./vr/useIsEnabledOverlaySmallLog";
export { useOverlaySettings } from "./vr/useOverlaySettings";

View File

@@ -0,0 +1,60 @@
import { useStore_CTranslate2WeightTypeStatus } from "@store";
import { useStdoutToPython } from "@logics/useStdoutToPython";
export const useCTranslate2WeightTypeStatus = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentCTranslate2WeightTypeStatus, updateCTranslate2WeightTypeStatus, pendingCTranslate2WeightTypeStatus } = useStore_CTranslate2WeightTypeStatus();
const updateDownloadedCTranslate2WeightTypeStatus = (downloaded_weight_type_status) => {
updateCTranslate2WeightTypeStatus((old_status) =>
old_status.data.map((item) => ({
...item,
is_downloaded: downloaded_weight_type_status[item.id] ?? item.is_downloaded,
}))
);
};
const updateDownloadProgressCTranslate2WeightTypeStatus = (payload) => {
if (payload === true) return console.error("fix me.");
updateCTranslate2WeightTypeStatus((old_status) =>
old_status.data.map((item) =>
payload.weight_type === item.id
? { ...item, progress: payload.progress * 100 }
: item
)
);
};
const pendingCTranslate2WeightType = (id) => {
updateCTranslate2WeightTypeStatus((old_status) =>
old_status.data.map((item) =>
id === item.id
? { ...item, is_pending: true }
: item
)
);
};
const downloadedCTranslate2WeightType = (id) => {
updateCTranslate2WeightTypeStatus((old_status) =>
old_status.data.map((item) =>
id === item.id
? { ...item, is_downloaded: true, is_pending: false, progress: null }
: item
)
);
};
const downloadCTranslate2Weight = (weight_type) => {
asyncStdoutToPython("/run/download_ctranslate2_weight", weight_type);
};
return {
currentCTranslate2WeightTypeStatus,
updateCTranslate2WeightTypeStatus,
updateDownloadedCTranslate2WeightTypeStatus,
updateDownloadProgressCTranslate2WeightTypeStatus,
pendingCTranslate2WeightType,
downloadedCTranslate2WeightType,
downloadCTranslate2Weight,
};
};

View File

@@ -0,0 +1,24 @@
import { useStore_SelectedCTranslate2WeightType } from "@store";
import { useStdoutToPython } from "@logics/useStdoutToPython";
export const useSelectedCTranslate2WeightType = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentSelectedCTranslate2WeightType, updateSelectedCTranslate2WeightType, pendingSelectedCTranslate2WeightType } = useStore_SelectedCTranslate2WeightType();
const getSelectedCTranslate2WeightType = () => {
pendingSelectedCTranslate2WeightType();
asyncStdoutToPython("/get/data/ctranslate2_weight_type");
};
const setSelectedCTranslate2WeightType = (selected_ctranslate2_weight_type) => {
pendingSelectedCTranslate2WeightType();
asyncStdoutToPython("/set/data/ctranslate2_weight_type", selected_ctranslate2_weight_type);
};
return {
currentSelectedCTranslate2WeightType,
getSelectedCTranslate2WeightType,
updateSelectedCTranslate2WeightType,
setSelectedCTranslate2WeightType,
};
};

View File

@@ -46,6 +46,8 @@ import {
useSpeakerPhraseTimeout,
useSpeakerMaxWords,
useDeepLAuthKey,
useCTranslate2WeightTypeStatus,
useSelectedCTranslate2WeightType,
useOverlaySettings,
useIsEnabledOverlaySmallLog,
useOverlaySmallLogSettings,
@@ -118,6 +120,12 @@ export const useReceiveRoutes = () => {
const { updateSpeakerMaxWords } = useSpeakerMaxWords();
const { updateDeepLAuthKey } = useDeepLAuthKey();
const { updateSelectedCTranslate2WeightType } = useSelectedCTranslate2WeightType();
const {
updateDownloadedCTranslate2WeightTypeStatus,
updateDownloadProgressCTranslate2WeightTypeStatus,
downloadedCTranslate2WeightType,
} = useCTranslate2WeightTypeStatus();
const { updateOverlaySettings } = useOverlaySettings();
const { updateOverlaySmallLogSettings } = useOverlaySmallLogSettings();
@@ -278,6 +286,14 @@ export const useReceiveRoutes = () => {
"/set/data/deepl_auth_key": updateDeepLAuthKey,
"/delete/data/deepl_auth_key": () => updateDeepLAuthKey(""),
"/get/data/ctranslate2_weight_type": updateSelectedCTranslate2WeightType,
"/set/data/ctranslate2_weight_type": updateSelectedCTranslate2WeightType,
"/get/data/selectable_ctranslate2_weight_type_dict": updateDownloadedCTranslate2WeightTypeStatus,
"/run/download_ctranslate2_weight": updateDownloadProgressCTranslate2WeightTypeStatus,
"/run/downloaded_ctranslate2_weight": downloadedCTranslate2WeightType,
// Transcription
"/get/data/mic_record_timeout": updateMicRecordTimeout,
"/set/data/mic_record_timeout": updateMicRecordTimeout,