From 0666a329479cc48d45f3bd487dc1813d1bd252d3 Mon Sep 17 00:00:00 2001 From: Qing Date: Sun, 13 Nov 2022 13:14:37 +0800 Subject: [PATCH] add --disable-model-switch --- lama_cleaner/app/src/adapters/inpainting.ts | 6 ++++++ .../components/Settings/ModelSettingBlock.tsx | 16 +++++++++++++++- .../app/src/components/shared/Selector.scss | 5 +++++ .../app/src/components/shared/Selector.tsx | 4 ++++ lama_cleaner/parse_args.py | 1 + lama_cleaner/server.py | 11 ++++++++++- 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lama_cleaner/app/src/adapters/inpainting.ts b/lama_cleaner/app/src/adapters/inpainting.ts index 5f74eb7..2cb6206 100644 --- a/lama_cleaner/app/src/adapters/inpainting.ts +++ b/lama_cleaner/app/src/adapters/inpainting.ts @@ -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) diff --git a/lama_cleaner/app/src/components/Settings/ModelSettingBlock.tsx b/lama_cleaner/app/src/components/Settings/ModelSettingBlock.tsx index d39f0d2..d722628 100644 --- a/lama_cleaner/app/src/components/Settings/ModelSettingBlock.tsx +++ b/lama_cleaner/app/src/components/Settings/ModelSettingBlock.tsx @@ -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()} diff --git a/lama_cleaner/app/src/components/shared/Selector.scss b/lama_cleaner/app/src/components/shared/Selector.scss index a54ffd5..18ecd41 100644 --- a/lama_cleaner/app/src/components/shared/Selector.scss +++ b/lama_cleaner/app/src/components/shared/Selector.scss @@ -24,6 +24,11 @@ // &:focus-visible { // border-color: var(--yellow-accent); // } + + &:disabled { + color: var(--border-color); + border-color: var(--border-color); + } } .select-content { diff --git a/lama_cleaner/app/src/components/shared/Selector.tsx b/lama_cleaner/app/src/components/shared/Selector.tsx index 3635382..dc0266f 100644 --- a/lama_cleaner/app/src/components/shared/Selector.tsx +++ b/lama_cleaner/app/src/components/shared/Selector.tsx @@ -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(null) @@ -52,6 +54,7 @@ const Selector = (props: Props) => { style={{ width }} ref={contentRef} onKeyDown={e => e.preventDefault()} + disabled={disabled} > @@ -78,6 +81,7 @@ const Selector = (props: Props) => { const selectorDefaultProps = { chevronDirection: 'down', autoFocusAfterClose: true, + disabled: false, } Selector.defaultProps = selectorDefaultProps diff --git a/lama_cleaner/parse_args.py b/lama_cleaner/parse_args.py index e06e663..8308d2f 100644 --- a/lama_cleaner/parse_args.py +++ b/lama_cleaner/parse_args.py @@ -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() diff --git a/lama_cleaner/server.py b/lama_cleaner/server.py index 6d1597c..6c763f6 100644 --- a/lama_cleaner/server.py +++ b/lama_cleaner/server.py @@ -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/") 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,