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) { export function switchModel(name: string) {
const fd = new FormData() const fd = new FormData()
fd.append('name', name) 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 { useRecoilState } from 'recoil'
import { getIsDisableModelSwitch } from '../../adapters/inpainting'
import { AIModel, CV2Flag, SDSampler, settingState } from '../../store/Atoms' import { AIModel, CV2Flag, SDSampler, settingState } from '../../store/Atoms'
import Selector from '../shared/Selector' import Selector from '../shared/Selector'
import { Switch, SwitchThumb } from '../shared/Switch' import { Switch, SwitchThumb } from '../shared/Switch'
@@ -10,6 +11,18 @@ import SettingBlock from './SettingBlock'
function ModelSettingBlock() { function ModelSettingBlock() {
const [setting, setSettingState] = useRecoilState(settingState) 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) => { const onModelChange = (value: AIModel) => {
setSettingState(old => { setSettingState(old => {
@@ -250,6 +263,7 @@ function ModelSettingBlock() {
value={setting.model as string} value={setting.model as string}
options={Object.values(AIModel)} options={Object.values(AIModel)}
onChange={val => onModelChange(val as AIModel)} onChange={val => onModelChange(val as AIModel)}
disabled={isDisableModelSwitch}
/> />
} }
optionDesc={renderOptionDesc()} optionDesc={renderOptionDesc()}

View File

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

View File

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

View File

@@ -44,6 +44,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
"--input", type=str, help="Path to image you want to load by default" "--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") parser.add_argument("--debug", action="store_true")
args = parser.parse_args() args = parser.parse_args()

View File

@@ -73,7 +73,7 @@ CORS(app, expose_headers=["Content-Disposition"])
model: ModelManager = None model: ModelManager = None
device = None device = None
input_image_path: str = None input_image_path: str = None
is_disable_model_switch: bool = False
def get_image_ext(img_bytes): def get_image_ext(img_bytes):
w = imghdr.what("", img_bytes) w = imghdr.what("", img_bytes)
@@ -170,6 +170,11 @@ def process():
def current_model(): def current_model():
return model.name, 200 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>") @app.route("/model_downloaded/<name>")
def model_downloaded(name): def model_downloaded(name):
@@ -213,9 +218,13 @@ def main(args):
global model global model
global device global device
global input_image_path global input_image_path
global is_disable_model_switch
device = torch.device(args.device) device = torch.device(args.device)
input_image_path = args.input 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( model = ModelManager(
name=args.model, name=args.model,