From d05ba042c04b8dd47cc5f16018e772da8e08fc43 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Thu, 12 Sep 2024 14:00:24 +0200 Subject: [PATCH] Make the optional AUTOMATIC1111 values nullable This commit makes the optional AUTOMATIC1111 options default to None, and if the value is removed, it resets to None. Signed-off-by: Balazs Toldi --- backend/open_webui/apps/images/main.py | 14 ++++++-------- backend/open_webui/config.py | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/backend/open_webui/apps/images/main.py b/backend/open_webui/apps/images/main.py index 773a685d9..390273a26 100644 --- a/backend/open_webui/apps/images/main.py +++ b/backend/open_webui/apps/images/main.py @@ -111,9 +111,9 @@ class OpenAIConfigForm(BaseModel): class Automatic1111ConfigForm(BaseModel): AUTOMATIC1111_BASE_URL: str AUTOMATIC1111_API_AUTH: str - AUTOMATIC1111_CFG_SCALE: float - AUTOMATIC1111_SAMPLER: str - AUTOMATIC1111_SCHEDULER: str + AUTOMATIC1111_CFG_SCALE: Optional[str] + AUTOMATIC1111_SAMPLER: Optional[str] + AUTOMATIC1111_SCHEDULER: Optional[str] class ComfyUIConfigForm(BaseModel): @@ -144,12 +144,10 @@ async def update_config(form_data: ConfigForm, user=Depends(get_admin_user)): app.state.config.AUTOMATIC1111_API_AUTH = ( form_data.automatic1111.AUTOMATIC1111_API_AUTH ) - app.state.config.AUTOMATIC1111_CFG_SCALE = form_data.automatic1111.AUTOMATIC1111_CFG_SCALE - app.state.config.AUTOMATIC1111_SAMPLER = form_data.automatic1111.AUTOMATIC1111_SAMPLER - app.state.config.AUTOMATIC1111_SCHEDULER = ( - form_data.automatic1111.AUTOMATIC1111_SCHEDULER - ) + app.state.config.AUTOMATIC1111_CFG_SCALE = float(form_data.automatic1111.AUTOMATIC1111_CFG_SCALE) if form_data.automatic1111.AUTOMATIC1111_CFG_SCALE != "" else None + app.state.config.AUTOMATIC1111_SAMPLER = form_data.automatic1111.AUTOMATIC1111_SAMPLER if form_data.automatic1111.AUTOMATIC1111_SAMPLER != "" else None + app.state.config.AUTOMATIC1111_SCHEDULER = form_data.automatic1111.AUTOMATIC1111_SCHEDULER if form_data.automatic1111.AUTOMATIC1111_SCHEDULER != "" else None app.state.config.COMFYUI_BASE_URL = form_data.comfyui.COMFYUI_BASE_URL.strip("/") app.state.config.COMFYUI_WORKFLOW = form_data.comfyui.COMFYUI_WORKFLOW diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index e252a0dbb..d5f9de4f3 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -1270,19 +1270,33 @@ AUTOMATIC1111_API_AUTH = PersistentConfig( AUTOMATIC1111_CFG_SCALE = PersistentConfig( "AUTOMATIC1111_CFG_SCALE", "image_generation.automatic1111.cfg_scale", - float(os.getenv("AUTOMATIC1111_CFG_SCALE", 7.0)), + ( + float(os.environ.get("AUTOMATIC1111_CFG_SCALE")) + if os.environ.get("AUTOMATIC1111_CFG_SCALE") + else None + ), ) + AUTOMATIC1111_SAMPLER = PersistentConfig( "AUTOMATIC1111_SAMPLERE", "image_generation.automatic1111.sampler", - os.getenv("AUTOMATIC1111_SAMPLER", "Euler"), + ( + os.environ.get("AUTOMATIC1111_SAMPLER") + if os.environ.get("AUTOMATIC1111_SAMPLER") + else None + ) + ) AUTOMATIC1111_SCHEDULER = PersistentConfig( "AUTOMATIC1111_SCHEDULER", "image_generation.automatic1111.scheduler", - os.getenv("AUTOMATIC1111_SCHEDULER", "Automatic"), + ( + os.environ.get("AUTOMATIC1111_SCHEDULER") + if os.environ.get("AUTOMATIC1111_SCHEDULER") + else None + ) ) COMFYUI_BASE_URL = PersistentConfig(