Use typing.Optional instead of | to add support for Python 3.9 and below.

This commit is contained in:
Billy Cao 2022-11-05 11:38:24 +08:00
parent 30b1bcc64e
commit ebce0c57c7

View File

@ -1,6 +1,6 @@
import inspect import inspect
from pydantic import BaseModel, Field, create_model from pydantic import BaseModel, Field, create_model
from typing import Any, Optional, Union from typing import Any, Optional
from typing_extensions import Literal from typing_extensions import Literal
from inflection import underscore from inflection import underscore
from modules.processing import StableDiffusionProcessingTxt2Img, StableDiffusionProcessingImg2Img from modules.processing import StableDiffusionProcessingTxt2Img, StableDiffusionProcessingImg2Img
@ -186,21 +186,21 @@ for key in _options:
if(_options[key].dest != 'help'): if(_options[key].dest != 'help'):
flag = _options[key] flag = _options[key]
_type = str _type = str
if(_options[key].default != None): _type = type(_options[key].default) if _options[key].default is not None: _type = type(_options[key].default)
flags.update({flag.dest: (_type,Field(default=flag.default, description=flag.help))}) flags.update({flag.dest: (_type,Field(default=flag.default, description=flag.help))})
FlagsModel = create_model("Flags", **flags) FlagsModel = create_model("Flags", **flags)
class SamplerItem(BaseModel): class SamplerItem(BaseModel):
name: str = Field(title="Name") name: str = Field(title="Name")
aliases: list[str] = Field(title="Aliases") aliases: list[str] = Field(title="Aliases")
options: dict[str, str] = Field(title="Options") options: dict[str, str] = Field(title="Options")
class UpscalerItem(BaseModel): class UpscalerItem(BaseModel):
name: str = Field(title="Name") name: str = Field(title="Name")
model_name: str | None = Field(title="Model Name") model_name: Optional[str] = Field(title="Model Name")
model_path: str | None = Field(title="Path") model_path: Optional[str] = Field(title="Path")
model_url: str | None = Field(title="URL") model_url: Optional[str] = Field(title="URL")
class SDModelItem(BaseModel): class SDModelItem(BaseModel):
title: str = Field(title="Title") title: str = Field(title="Title")
@ -211,21 +211,21 @@ class SDModelItem(BaseModel):
class HypernetworkItem(BaseModel): class HypernetworkItem(BaseModel):
name: str = Field(title="Name") name: str = Field(title="Name")
path: str | None = Field(title="Path") path: Optional[str] = Field(title="Path")
class FaceRestorerItem(BaseModel): class FaceRestorerItem(BaseModel):
name: str = Field(title="Name") name: str = Field(title="Name")
cmd_dir: str | None = Field(title="Path") cmd_dir: Optional[str] = Field(title="Path")
class RealesrganItem(BaseModel): class RealesrganItem(BaseModel):
name: str = Field(title="Name") name: str = Field(title="Name")
path: str | None = Field(title="Path") path: Optional[str] = Field(title="Path")
scale: int | None = Field(title="Scale") scale: Optional[int] = Field(title="Scale")
class PromptStyleItem(BaseModel): class PromptStyleItem(BaseModel):
name: str = Field(title="Name") name: str = Field(title="Name")
prompt: str | None = Field(title="Prompt") prompt: Optional[str] = Field(title="Prompt")
negative_prompt: str | None = Field(title="Negative Prompt") negative_prompt: Optional[str] = Field(title="Negative Prompt")
class ArtistItem(BaseModel): class ArtistItem(BaseModel):
name: str = Field(title="Name") name: str = Field(title="Name")