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-01-12 17:01:45 +03:00
|
|
|
import { ClientState } from "@dannadori/voice-changer-client-js";
|
2023-01-07 14:07:39 +03:00
|
|
|
|
2023-01-07 18:25:21 +03:00
|
|
|
export type UseServerSettingProps = {
|
2023-01-08 10:18:20 +03:00
|
|
|
clientState: ClientState
|
2023-01-07 18:25:21 +03:00
|
|
|
}
|
|
|
|
|
2023-01-07 14:07:39 +03:00
|
|
|
export type ServerSettingState = {
|
|
|
|
serverSetting: JSX.Element;
|
|
|
|
}
|
|
|
|
|
2023-01-12 10:38:45 +03:00
|
|
|
export const useServerSettingArea = (props: UseServerSettingProps): ServerSettingState => {
|
2023-01-28 10:06:21 +03:00
|
|
|
const [showPyTorch, setShowPyTorch] = useState<boolean>(false)
|
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-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.setFileUploadSetting({
|
|
|
|
...props.clientState.serverSetting.fileUploadSetting,
|
2023-01-10 18:59:09 +03:00
|
|
|
pyTorchModel: file
|
|
|
|
})
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
2023-01-08 14:28:57 +03:00
|
|
|
const onPyTorchFileClearClicked = () => {
|
2023-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.setFileUploadSetting({
|
|
|
|
...props.clientState.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-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.setFileUploadSetting({
|
|
|
|
...props.clientState.serverSetting.fileUploadSetting,
|
2023-01-10 18:59:09 +03:00
|
|
|
configFile: file
|
|
|
|
})
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
2023-01-08 14:28:57 +03:00
|
|
|
const onConfigFileClearClicked = () => {
|
2023-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.setFileUploadSetting({
|
|
|
|
...props.clientState.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-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.setFileUploadSetting({
|
|
|
|
...props.clientState.serverSetting.fileUploadSetting,
|
2023-01-10 18:59:09 +03:00
|
|
|
onnxModel: file
|
|
|
|
})
|
2023-01-07 14:07:39 +03:00
|
|
|
}
|
2023-01-08 14:28:57 +03:00
|
|
|
const onOnnxFileClearClicked = () => {
|
2023-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.setFileUploadSetting({
|
|
|
|
...props.clientState.serverSetting.fileUploadSetting,
|
2023-01-10 18:59:09 +03:00
|
|
|
onnxModel: null
|
|
|
|
})
|
2023-01-08 14:28:57 +03:00
|
|
|
}
|
2023-01-07 18:25:21 +03:00
|
|
|
const onModelUploadClicked = async () => {
|
2023-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.loadModel()
|
2023-01-07 18:25:21 +03:00
|
|
|
}
|
|
|
|
|
2023-01-14 11:58:57 +03:00
|
|
|
const uploadButtonClassName = props.clientState.serverSetting.isUploading ? "body-button-disabled" : "body-button"
|
|
|
|
const uploadButtonAction = props.clientState.serverSetting.isUploading ? () => { } : onModelUploadClicked
|
|
|
|
const uploadButtonLabel = props.clientState.serverSetting.isUploading ? "wait..." : "upload"
|
|
|
|
|
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>
|
|
|
|
<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-12 10:38:45 +03:00
|
|
|
<div>{props.clientState.serverSetting.fileUploadSetting.configFile?.name}</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>
|
|
|
|
<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-12 10:38:45 +03:00
|
|
|
<div>{props.clientState.serverSetting.fileUploadSetting.onnxModel?.name}</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">
|
|
|
|
<div>{props.clientState.serverSetting.fileUploadSetting.pyTorchModel?.name}</div>
|
|
|
|
</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-01-12 10:38:45 +03:00
|
|
|
{props.clientState.serverSetting.isUploading ? `uploading.... ${props.clientState.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-01-12 10:38:45 +03:00
|
|
|
props.clientState.serverSetting.fileUploadSetting,
|
|
|
|
props.clientState.serverSetting.loadModel,
|
|
|
|
props.clientState.serverSetting.isUploading,
|
2023-01-28 10:06:21 +03:00
|
|
|
props.clientState.serverSetting.uploadProgress,
|
|
|
|
showPyTorch])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
|
|
|
const frameworkRow = useMemo(() => {
|
|
|
|
const onFrameworkChanged = async (val: Framework) => {
|
2023-01-12 10:38:45 +03:00
|
|
|
props.clientState.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-01-12 10:38:45 +03:00
|
|
|
<select className="body-select" value={props.clientState.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-01-12 10:38:45 +03:00
|
|
|
}, [props.clientState.serverSetting.setting.framework, props.clientState.serverSetting.setFramework])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
|
|
|
const onnxExecutionProviderRow = useMemo(() => {
|
2023-01-12 10:38:45 +03:00
|
|
|
if (props.clientState.serverSetting.setting.framework != "ONNX") {
|
2023-01-07 14:07:39 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
const onOnnxExecutionProviderChanged = async (val: OnnxExecutionProvider) => {
|
2023-01-12 10:38:45 +03:00
|
|
|
props.clientState.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-01-12 10:38:45 +03:00
|
|
|
<select className="body-select" value={props.clientState.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-01-12 10:47:09 +03:00
|
|
|
}, [props.clientState.serverSetting.setting.framework, props.clientState.serverSetting.setting.onnxExecutionProvider, props.clientState.serverSetting.setOnnxExecutionProvider])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
|
|
|
const serverSetting = useMemo(() => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="body-row split-3-7 left-padding-1">
|
|
|
|
<div className="body-sub-section-title">Server Setting</div>
|
|
|
|
<div className="body-select-container">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{uploadeModelRow}
|
|
|
|
{frameworkRow}
|
|
|
|
{onnxExecutionProviderRow}
|
|
|
|
</>
|
|
|
|
)
|
2023-01-12 11:43:36 +03:00
|
|
|
}, [uploadeModelRow, frameworkRow, onnxExecutionProviderRow])
|
2023-01-07 14:07:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
serverSetting,
|
|
|
|
}
|
|
|
|
}
|