diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2022-11-04 08:00:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-04 08:00:32 +0000 |
commit | e9c767d8dba884762b39d36fbd7cd43f818acf24 (patch) | |
tree | b1d1a0cb9a445443ec18524b0c3906e94d21a26e /modules/api/models.py | |
parent | b2c48091db394c2b7d375a33f18d90c924cd4363 (diff) | |
parent | 2913b9f02500049c76c3d1469c086767411cefa9 (diff) | |
download | stable-diffusion-webui-gfx803-e9c767d8dba884762b39d36fbd7cd43f818acf24.tar.gz stable-diffusion-webui-gfx803-e9c767d8dba884762b39d36fbd7cd43f818acf24.tar.bz2 stable-diffusion-webui-gfx803-e9c767d8dba884762b39d36fbd7cd43f818acf24.zip |
Merge branch 'master' into 7flash/fix-api-compatibility
Diffstat (limited to 'modules/api/models.py')
-rw-r--r-- | modules/api/models.py | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/modules/api/models.py b/modules/api/models.py index 29a934ba..2ae75f43 100644 --- a/modules/api/models.py +++ b/modules/api/models.py @@ -1,11 +1,10 @@ import inspect -from click import prompt from pydantic import BaseModel, Field, create_model -from typing import Any, Optional +from typing import Any, Optional, Union from typing_extensions import Literal from inflection import underscore from modules.processing import StableDiffusionProcessingTxt2Img, StableDiffusionProcessingImg2Img -from modules.shared import sd_upscalers +from modules.shared import sd_upscalers, opts, parser from typing import List API_NOT_ALLOWED = [ @@ -132,6 +131,7 @@ class ExtrasBaseRequest(BaseModel): upscaler_1: str = Field(default="None", title="Main upscaler", description=f"The name of the main upscaler to use, it has to be one of this list: {' , '.join([x.name for x in sd_upscalers])}") upscaler_2: str = Field(default="None", title="Secondary upscaler", description=f"The name of the secondary upscaler to use, it has to be one of this list: {' , '.join([x.name for x in sd_upscalers])}") extras_upscaler_2_visibility: float = Field(default=0, title="Secondary upscaler visibility", ge=0, le=1, allow_inf_nan=False, description="Sets the visibility of secondary upscaler, values should be between 0 and 1.") + upscale_first: bool = Field(default=False, title="Upscale first", description="Should the upscaler run before restoring faces?") class ExtraBaseResponse(BaseModel): html_info: str = Field(title="HTML info", description="A series of HTML tags containing the process info.") @@ -166,3 +166,68 @@ class ProgressResponse(BaseModel): eta_relative: float = Field(title="ETA in secs") state: dict = Field(title="State", description="The current state snapshot") current_image: str = Field(default=None, title="Current image", description="The current image in base64 format. opts.show_progress_every_n_steps is required for this to work.") + +fields = {} +for key, value in opts.data.items(): + metadata = opts.data_labels.get(key) + optType = opts.typemap.get(type(value), type(value)) + + if (metadata is not None): + fields.update({key: (Optional[optType], Field( + default=metadata.default ,description=metadata.label))}) + else: + fields.update({key: (Optional[optType], Field())}) + +OptionsModel = create_model("Options", **fields) + +flags = {} +_options = vars(parser)['_option_string_actions'] +for key in _options: + if(_options[key].dest != 'help'): + flag = _options[key] + _type = str + if(_options[key].default != None): _type = type(_options[key].default) + flags.update({flag.dest: (_type,Field(default=flag.default, description=flag.help))}) + +FlagsModel = create_model("Flags", **flags) + +class SamplerItem(BaseModel): + name: str = Field(title="Name") + aliases: list[str] = Field(title="Aliases") + options: dict[str, str] = Field(title="Options") + +class UpscalerItem(BaseModel): + name: str = Field(title="Name") + model_name: str | None = Field(title="Model Name") + model_path: str | None = Field(title="Path") + model_url: str | None = Field(title="URL") + +class SDModelItem(BaseModel): + title: str = Field(title="Title") + model_name: str = Field(title="Model Name") + hash: str = Field(title="Hash") + filename: str = Field(title="Filename") + config: str = Field(title="Config file") + +class HypernetworkItem(BaseModel): + name: str = Field(title="Name") + path: str | None = Field(title="Path") + +class FaceRestorerItem(BaseModel): + name: str = Field(title="Name") + cmd_dir: str | None = Field(title="Path") + +class RealesrganItem(BaseModel): + name: str = Field(title="Name") + path: str | None = Field(title="Path") + scale: int | None = Field(title="Scale") + +class PromptStyleItem(BaseModel): + name: str = Field(title="Name") + prompt: str | None = Field(title="Prompt") + negative_prompt: str | None = Field(title="Negative Prompt") + +class ArtistItem(BaseModel): + name: str = Field(title="Name") + score: float = Field(title="Score") + category: str = Field(title="Category")
\ No newline at end of file |