add --disable-model-switch

This commit is contained in:
Qing 2022-11-13 13:14:37 +08:00
parent 8cdac238b4
commit 0666a32947
6 changed files with 41 additions and 2 deletions

View File

@ -75,6 +75,12 @@ export default async function inpaint(
}
}
export function getIsDisableModelSwitch() {
return fetch(`${API_ENDPOINT}/is_disable_model_switch`, {
method: 'GET',
})
}
export function switchModel(name: string) {
const fd = new FormData()
fd.append('name', name)

View File

@ -1,5 +1,6 @@
import React, { ReactNode } from 'react'
import React, { ReactNode, useEffect, useState } from 'react'
import { useRecoilState } from 'recoil'
import { getIsDisableModelSwitch } from '../../adapters/inpainting'
import { AIModel, CV2Flag, SDSampler, settingState } from '../../store/Atoms'
import Selector from '../shared/Selector'
import { Switch, SwitchThumb } from '../shared/Switch'
@ -10,6 +11,18 @@ import SettingBlock from './SettingBlock'
function ModelSettingBlock() {
const [setting, setSettingState] = useRecoilState(settingState)
const [isDisableModelSwitch, setIsDisableModelSwitch] = useState(false)
useEffect(() => {
const fetchData = async () => {
const isDisable: string = await getIsDisableModelSwitch().then(res =>
res.text()
)
setIsDisableModelSwitch(isDisable === 'true')
}
fetchData()
}, [])
const onModelChange = (value: AIModel) => {
setSettingState(old => {
@ -250,6 +263,7 @@ function ModelSettingBlock() {
value={setting.model as string}
options={Object.values(AIModel)}
onChange={val => onModelChange(val as AIModel)}
disabled={isDisableModelSwitch}
/>
}
optionDesc={renderOptionDesc()}

View File

@ -24,6 +24,11 @@
// &:focus-visible {
// border-color: var(--yellow-accent);
// }
&:disabled {
color: var(--border-color);
border-color: var(--border-color);
}
}
.select-content {

View File

@ -15,6 +15,7 @@ interface Props {
chevronDirection?: SelectorChevronDirection
autoFocusAfterClose?: boolean
onChange: (value: string) => void
disabled?: boolean
}
const Selector = (props: Props) => {
@ -25,6 +26,7 @@ const Selector = (props: Props) => {
options,
autoFocusAfterClose,
onChange,
disabled,
} = props
const contentRef = useRef<HTMLButtonElement>(null)
@ -52,6 +54,7 @@ const Selector = (props: Props) => {
style={{ width }}
ref={contentRef}
onKeyDown={e => e.preventDefault()}
disabled={disabled}
>
<Select.Value />
<Select.Icon>
@ -78,6 +81,7 @@ const Selector = (props: Props) => {
const selectorDefaultProps = {
chevronDirection: 'down',
autoFocusAfterClose: true,
disabled: false,
}
Selector.defaultProps = selectorDefaultProps

View File

@ -44,6 +44,7 @@ def parse_args():
parser.add_argument(
"--input", type=str, help="Path to image you want to load by default"
)
parser.add_argument("--disable-model-switch", action="store_true", help="Disable model switch in frontend")
parser.add_argument("--debug", action="store_true")
args = parser.parse_args()

View File

@ -73,7 +73,7 @@ CORS(app, expose_headers=["Content-Disposition"])
model: ModelManager = None
device = None
input_image_path: str = None
is_disable_model_switch: bool = False
def get_image_ext(img_bytes):
w = imghdr.what("", img_bytes)
@ -170,6 +170,11 @@ def process():
def current_model():
return model.name, 200
@app.route("/is_disable_model_switch")
def get_is_disable_model_switch():
res = 'true' if is_disable_model_switch else 'false'
return res, 200
@app.route("/model_downloaded/<name>")
def model_downloaded(name):
@ -213,9 +218,13 @@ def main(args):
global model
global device
global input_image_path
global is_disable_model_switch
device = torch.device(args.device)
input_image_path = args.input
is_disable_model_switch = args.disable_model_switch
if is_disable_model_switch:
logger.info(f"Start with --disable-model-switch, model switch on frontend is disable")
model = ModelManager(
name=args.model,