2023-01-12 15:42:02 +03:00
|
|
|
import { OnnxExecutionProvider, Framework, fileSelector } from "@dannadori/voice-changer-client-js"
|
2023-01-28 10:06:21 +03:00
|
|
|
import React, { useState } from "react"
|
2023-01-10 18:59:09 +03:00
|
|
|
import { useMemo } from "react"
|
2023-02-16 18:09:56 +03:00
|
|
|
import { useAppState } from "./001_provider/001_AppStateProvider";
|
|
|
|
import { AnimationTypes, HeaderButton, HeaderButtonProps } from "./components/101_HeaderButton";
|
2023-01-07 18:25:21 +03:00
|
|
|
|
2023-01-07 14:07:39 +03:00
|
|
|
export type ServerSettingState = {
|
2023-02-16 18:09:56 +03:00
|
|
|
modelSetting: JSX.Element;
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:09:56 +03:00
|
|
|
export const useModelSettingArea = (): ServerSettingState => {
|
|
|
|
const appState = useAppState()
|
2023-02-10 19:04:19 +03:00
|
|
|
const [showPyTorch, setShowPyTorch] = useState<boolean>(true)
|
2023-02-16 18:09:56 +03:00
|
|
|
const [showDetail, setShowDetail] = useState<boolean>(true)
|
|
|
|
|
|
|
|
|
|
|
|
const accodionButton = useMemo(() => {
|
|
|
|
const accodionButtonProps: HeaderButtonProps = {
|
|
|
|
stateControlCheckbox: appState.frontendManagerState.stateControls.openModelSettingCheckbox,
|
|
|
|
tooltip: "Open/Close",
|
|
|
|
onIcon: ["fas", "caret-up"],
|
|
|
|
offIcon: ["fas", "caret-up"],
|
|
|
|
animation: AnimationTypes.spinner,
|
|
|
|
tooltipClass: "tooltip-right",
|
|
|
|
};
|
|
|
|
return <HeaderButton {...accodionButtonProps}></HeaderButton>;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
// If already model is set, show summarry.
|
|
|
|
const settingDone = useMemo(() => {
|
|
|
|
if (
|
|
|
|
appState.serverSetting.fileUploadSetting.configFile?.filename && // Config file
|
|
|
|
(
|
|
|
|
appState.serverSetting.fileUploadSetting.onnxModel?.filename || // Model file
|
|
|
|
appState.serverSetting.fileUploadSetting.pyTorchModel?.filename
|
|
|
|
) &&
|
|
|
|
appState.clientSetting.setting.correspondences.length > 0 // Corresopondence file
|
|
|
|
) {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
appState.serverSetting.fileUploadSetting,
|
|
|
|
appState.clientSetting.setting.correspondences
|
|
|
|
])
|
|
|
|
|
|
|
|
const uploadeModelSummaryRow = useMemo(() => {
|
|
|
|
|
|
|
|
|
|
|
|
}, [settingDone, showDetail])
|
|
|
|
|
2023-01-07 14:07:39 +03:00
|
|
|
const uploadeModelRow = useMemo(() => {
|
|
|
|
const onPyTorchFileLoadClicked = async () => {
|
|
|
|
const file = await fileSelector("")
|
|
|
|
if (file.name.endsWith(".pth") == false) {
|
|
|
|
alert("モデルファイルの拡張子はpthである必要があります。")
|
|
|
|
return
|
|
|
|
}
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setFileUploadSetting({
|
|
|
|
...appState.serverSetting.fileUploadSetting,
|
2023-01-29 08:41:44 +03:00
|
|
|
pyTorchModel: {
|
2023-01-29 09:25:44 +03:00
|
|
|
file: file
|
2023-01-29 08:41:44 +03:00
|
|
|
}
|
2023-01-10 18:59:09 +03:00
|
|
|
})
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
2023-01-08 14:28:57 +03:00
|
|
|
const onPyTorchFileClearClicked = () => {
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setFileUploadSetting({
|
|
|
|
...appState.serverSetting.fileUploadSetting,
|
2023-01-10 18:59:09 +03:00
|
|
|
pyTorchModel: null
|
|
|
|
})
|
2023-01-08 14:28:57 +03:00
|
|
|
}
|
2023-01-07 14:07:39 +03:00
|
|
|
const onConfigFileLoadClicked = async () => {
|
|
|
|
const file = await fileSelector("")
|
|
|
|
if (file.name.endsWith(".json") == false) {
|
|
|
|
alert("モデルファイルの拡張子はjsonである必要があります。")
|
|
|
|
return
|
|
|
|
}
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setFileUploadSetting({
|
|
|
|
...appState.serverSetting.fileUploadSetting,
|
2023-01-29 08:41:44 +03:00
|
|
|
configFile: {
|
2023-01-29 09:25:44 +03:00
|
|
|
file: file
|
2023-01-29 08:41:44 +03:00
|
|
|
}
|
2023-01-10 18:59:09 +03:00
|
|
|
})
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
2023-01-08 14:28:57 +03:00
|
|
|
const onConfigFileClearClicked = () => {
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setFileUploadSetting({
|
|
|
|
...appState.serverSetting.fileUploadSetting,
|
2023-01-10 18:59:09 +03:00
|
|
|
configFile: null
|
|
|
|
})
|
2023-01-08 14:28:57 +03:00
|
|
|
}
|
2023-01-07 14:07:39 +03:00
|
|
|
const onOnnxFileLoadClicked = async () => {
|
|
|
|
const file = await fileSelector("")
|
|
|
|
if (file.name.endsWith(".onnx") == false) {
|
|
|
|
alert("モデルファイルの拡張子はonnxである必要があります。")
|
|
|
|
return
|
|
|
|
}
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setFileUploadSetting({
|
|
|
|
...appState.serverSetting.fileUploadSetting,
|
2023-01-29 08:41:44 +03:00
|
|
|
onnxModel: {
|
2023-01-29 09:25:44 +03:00
|
|
|
file: file
|
2023-01-29 08:41:44 +03:00
|
|
|
}
|
2023-01-10 18:59:09 +03:00
|
|
|
})
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
2023-01-08 14:28:57 +03:00
|
|
|
const onOnnxFileClearClicked = () => {
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setFileUploadSetting({
|
|
|
|
...appState.serverSetting.fileUploadSetting,
|
2023-01-10 18:59:09 +03:00
|
|
|
onnxModel: null
|
|
|
|
})
|
2023-01-08 14:28:57 +03:00
|
|
|
}
|
2023-02-12 06:25:57 +03:00
|
|
|
const onCorrespondenceFileLoadClicked = async () => {
|
|
|
|
const file = await fileSelector("")
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.clientSetting.setCorrespondences(file)
|
2023-02-12 06:25:57 +03:00
|
|
|
}
|
|
|
|
const onCorrespondenceFileClearClicked = () => {
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.clientSetting.setCorrespondences(null)
|
2023-02-12 06:25:57 +03:00
|
|
|
}
|
|
|
|
|
2023-01-07 18:25:21 +03:00
|
|
|
const onModelUploadClicked = async () => {
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.loadModel()
|
2023-01-07 18:25:21 +03:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:09:56 +03:00
|
|
|
const uploadButtonClassName = appState.serverSetting.isUploading ? "body-button-disabled" : "body-button"
|
|
|
|
const uploadButtonAction = appState.serverSetting.isUploading ? () => { } : onModelUploadClicked
|
|
|
|
const uploadButtonLabel = appState.serverSetting.isUploading ? "wait..." : "upload"
|
2023-01-14 11:58:57 +03:00
|
|
|
|
2023-02-16 18:09:56 +03:00
|
|
|
const configFilenameText = appState.serverSetting.fileUploadSetting.configFile?.filename || appState.serverSetting.fileUploadSetting.configFile?.file?.name || ""
|
|
|
|
const onnxModelFilenameText = appState.serverSetting.fileUploadSetting.onnxModel?.filename || appState.serverSetting.fileUploadSetting.onnxModel?.file?.name || ""
|
|
|
|
const pyTorchFilenameText = appState.serverSetting.fileUploadSetting.pyTorchModel?.filename || appState.serverSetting.fileUploadSetting.pyTorchModel?.file?.name || ""
|
|
|
|
const correspondenceFileText = appState.clientSetting.setting.correspondences ? JSON.stringify(appState.clientSetting.setting.correspondences.map(x => { return x.dirname })) : ""
|
2023-01-29 09:25:44 +03:00
|
|
|
|
2023-01-07 14:07:39 +03:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-1">Model Uploader</div>
|
|
|
|
<div className="body-item-text">
|
|
|
|
<div></div>
|
|
|
|
</div>
|
|
|
|
<div className="body-item-text">
|
2023-01-28 10:06:21 +03:00
|
|
|
<div>
|
|
|
|
<input type="checkbox" checked={showPyTorch} onChange={(e) => {
|
|
|
|
setShowPyTorch(e.target.checked)
|
|
|
|
}} /> enable PyTorch
|
|
|
|
</div>
|
2023-01-07 14:07:39 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-12 06:25:57 +03:00
|
|
|
|
2023-01-07 14:07:39 +03:00
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
2023-01-12 10:38:45 +03:00
|
|
|
<div className="body-item-title left-padding-2">Config(.json)</div>
|
2023-01-07 14:07:39 +03:00
|
|
|
<div className="body-item-text">
|
2023-01-29 09:25:44 +03:00
|
|
|
<div>{configFilenameText}</div>
|
2023-01-07 14:07:39 +03:00
|
|
|
</div>
|
|
|
|
<div className="body-button-container">
|
2023-01-12 10:38:45 +03:00
|
|
|
<div className="body-button" onClick={onConfigFileLoadClicked}>select</div>
|
|
|
|
<div className="body-button left-margin-1" onClick={onConfigFileClearClicked}>clear</div>
|
2023-01-07 14:07:39 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-12 06:25:57 +03:00
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-2">Correspondence</div>
|
|
|
|
<div className="body-item-text">
|
|
|
|
<div>{correspondenceFileText}</div>
|
|
|
|
</div>
|
|
|
|
<div className="body-button-container">
|
|
|
|
<div className="body-button" onClick={onCorrespondenceFileLoadClicked}>select</div>
|
|
|
|
<div className="body-button left-margin-1" onClick={onCorrespondenceFileClearClicked}>clear</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-01-07 14:07:39 +03:00
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-2">Onnx(.onnx)</div>
|
|
|
|
<div className="body-item-text">
|
2023-01-29 09:25:44 +03:00
|
|
|
<div>{onnxModelFilenameText}</div>
|
2023-01-07 14:07:39 +03:00
|
|
|
</div>
|
|
|
|
<div className="body-button-container">
|
|
|
|
<div className="body-button" onClick={onOnnxFileLoadClicked}>select</div>
|
2023-01-08 14:28:57 +03:00
|
|
|
<div className="body-button left-margin-1" onClick={onOnnxFileClearClicked}>clear</div>
|
2023-01-07 14:07:39 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-28 10:06:21 +03:00
|
|
|
{showPyTorch ?
|
|
|
|
(
|
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-2">PyTorch(.pth)</div>
|
|
|
|
<div className="body-item-text">
|
2023-01-29 09:25:44 +03:00
|
|
|
<div>{pyTorchFilenameText}</div>
|
2023-01-28 10:06:21 +03:00
|
|
|
</div>
|
|
|
|
<div className="body-button-container">
|
|
|
|
<div className="body-button" onClick={onPyTorchFileLoadClicked}>select</div>
|
|
|
|
<div className="body-button left-margin-1" onClick={onPyTorchFileClearClicked}>clear</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
|
|
|
:
|
|
|
|
(
|
|
|
|
<></>
|
|
|
|
)
|
|
|
|
}
|
2023-01-07 18:25:21 +03:00
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-2"></div>
|
|
|
|
<div className="body-item-text">
|
2023-02-16 18:09:56 +03:00
|
|
|
{appState.serverSetting.isUploading ? `uploading.... ${appState.serverSetting.uploadProgress}%` : ""}
|
2023-01-07 18:25:21 +03:00
|
|
|
</div>
|
|
|
|
<div className="body-button-container">
|
2023-01-14 11:58:57 +03:00
|
|
|
<div className={uploadButtonClassName} onClick={uploadButtonAction}>{uploadButtonLabel}</div>
|
2023-01-07 18:25:21 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-07 14:07:39 +03:00
|
|
|
</>
|
|
|
|
)
|
2023-01-10 18:59:09 +03:00
|
|
|
}, [
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.fileUploadSetting,
|
|
|
|
appState.serverSetting.loadModel,
|
|
|
|
appState.serverSetting.isUploading,
|
|
|
|
appState.serverSetting.uploadProgress,
|
|
|
|
appState.clientSetting.setting.correspondences,
|
2023-01-28 10:06:21 +03:00
|
|
|
showPyTorch])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
|
|
|
const frameworkRow = useMemo(() => {
|
|
|
|
const onFrameworkChanged = async (val: Framework) => {
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setFramework(val)
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className="body-row split-3-7 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-1">Framework</div>
|
|
|
|
<div className="body-select-container">
|
2023-02-16 18:09:56 +03:00
|
|
|
<select className="body-select" value={appState.serverSetting.setting.framework} onChange={(e) => {
|
2023-01-07 14:07:39 +03:00
|
|
|
onFrameworkChanged(e.target.value as
|
|
|
|
Framework)
|
|
|
|
}}>
|
|
|
|
{
|
|
|
|
Object.values(Framework).map(x => {
|
|
|
|
return <option key={x} value={x}>{x}</option>
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
2023-02-16 18:09:56 +03:00
|
|
|
}, [appState.serverSetting.setting.framework, appState.serverSetting.setFramework])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
|
|
|
const onnxExecutionProviderRow = useMemo(() => {
|
2023-02-16 18:09:56 +03:00
|
|
|
if (appState.serverSetting.setting.framework != "ONNX") {
|
2023-01-07 14:07:39 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
const onOnnxExecutionProviderChanged = async (val: OnnxExecutionProvider) => {
|
2023-02-16 18:09:56 +03:00
|
|
|
appState.serverSetting.setOnnxExecutionProvider(val)
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className="body-row split-3-7 left-padding-1">
|
|
|
|
<div className="body-item-title left-padding-2">OnnxExecutionProvider</div>
|
|
|
|
<div className="body-select-container">
|
2023-02-16 18:09:56 +03:00
|
|
|
<select className="body-select" value={appState.serverSetting.setting.onnxExecutionProvider} onChange={(e) => {
|
2023-01-07 14:07:39 +03:00
|
|
|
onOnnxExecutionProviderChanged(e.target.value as
|
|
|
|
OnnxExecutionProvider)
|
|
|
|
}}>
|
|
|
|
{
|
|
|
|
Object.values(OnnxExecutionProvider).map(x => {
|
|
|
|
return <option key={x} value={x}>{x}</option>
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
2023-02-16 18:09:56 +03:00
|
|
|
}, [appState.serverSetting.setting.framework, appState.serverSetting.setting.onnxExecutionProvider, appState.serverSetting.setOnnxExecutionProvider])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
2023-02-16 18:09:56 +03:00
|
|
|
const modelSetting = useMemo(() => {
|
2023-01-07 14:07:39 +03:00
|
|
|
return (
|
|
|
|
<>
|
2023-02-16 18:09:56 +03:00
|
|
|
{appState.frontendManagerState.stateControls.openModelSettingCheckbox.trigger}
|
|
|
|
<div className="partition">
|
|
|
|
<div className="partition-header">
|
|
|
|
<span className="caret">
|
|
|
|
{accodionButton}
|
|
|
|
</span>
|
|
|
|
<span className="title" onClick={() => { appState.frontendManagerState.stateControls.openModelSettingCheckbox.updateState(!appState.frontendManagerState.stateControls.openModelSettingCheckbox.checked()) }}>
|
|
|
|
Model Setting
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="partition-content">
|
|
|
|
{uploadeModelRow}
|
|
|
|
{frameworkRow}
|
|
|
|
{onnxExecutionProviderRow}
|
2023-01-07 14:07:39 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
2023-01-12 11:43:36 +03:00
|
|
|
}, [uploadeModelRow, frameworkRow, onnxExecutionProviderRow])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
return {
|
2023-02-16 18:09:56 +03:00
|
|
|
modelSetting,
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
|
|
|
}
|