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 <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2024-09-12 14:00:24 +02:00
parent 7f6dae41f0
commit d05ba042c0
2 changed files with 23 additions and 11 deletions

View File

@ -111,9 +111,9 @@ class OpenAIConfigForm(BaseModel):
class Automatic1111ConfigForm(BaseModel): class Automatic1111ConfigForm(BaseModel):
AUTOMATIC1111_BASE_URL: str AUTOMATIC1111_BASE_URL: str
AUTOMATIC1111_API_AUTH: str AUTOMATIC1111_API_AUTH: str
AUTOMATIC1111_CFG_SCALE: float AUTOMATIC1111_CFG_SCALE: Optional[str]
AUTOMATIC1111_SAMPLER: str AUTOMATIC1111_SAMPLER: Optional[str]
AUTOMATIC1111_SCHEDULER: str AUTOMATIC1111_SCHEDULER: Optional[str]
class ComfyUIConfigForm(BaseModel): 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 = ( app.state.config.AUTOMATIC1111_API_AUTH = (
form_data.automatic1111.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_BASE_URL = form_data.comfyui.COMFYUI_BASE_URL.strip("/")
app.state.config.COMFYUI_WORKFLOW = form_data.comfyui.COMFYUI_WORKFLOW app.state.config.COMFYUI_WORKFLOW = form_data.comfyui.COMFYUI_WORKFLOW

View File

@ -1270,19 +1270,33 @@ AUTOMATIC1111_API_AUTH = PersistentConfig(
AUTOMATIC1111_CFG_SCALE = PersistentConfig( AUTOMATIC1111_CFG_SCALE = PersistentConfig(
"AUTOMATIC1111_CFG_SCALE", "AUTOMATIC1111_CFG_SCALE",
"image_generation.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_SAMPLER = PersistentConfig(
"AUTOMATIC1111_SAMPLERE", "AUTOMATIC1111_SAMPLERE",
"image_generation.automatic1111.sampler", "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 = PersistentConfig(
"AUTOMATIC1111_SCHEDULER", "AUTOMATIC1111_SCHEDULER",
"image_generation.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( COMFYUI_BASE_URL = PersistentConfig(