From 8f1f538bc907a8eb8893fd1368c1b25e6c8fc16a Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 30 Jan 2024 16:19:03 -0500 Subject: [PATCH] add api compatibility layer for civitai --- modules/api/api.py | 9 ++++++--- modules/api/models.py | 17 +++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/modules/api/api.py b/modules/api/api.py index 1381c57ed..6810e6aab 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -10,9 +10,6 @@ from modules.processing import StableDiffusionProcessingTxt2Img, StableDiffusion errors.install() -decode_base64_to_image = helpers.decode_base64_to_image -encode_pil_to_base64 = helpers.encode_pil_to_base64 -validate_sampler_name = helpers.validate_sampler_name class Api: @@ -287,3 +284,9 @@ class Api: http_server.start() shared.log.info(f'API server: Uvicorn options={config}') return http_server + + +# compatibility items +decode_base64_to_image = helpers.decode_base64_to_image +encode_pil_to_base64 = helpers.encode_pil_to_base64 +validate_sampler_name = helpers.validate_sampler_name diff --git a/modules/api/models.py b/modules/api/models.py index a03926d33..cf402ea14 100644 --- a/modules/api/models.py +++ b/modules/api/models.py @@ -22,8 +22,6 @@ API_NOT_ALLOWED = [ ] class ModelDef(BaseModel): - """Assistance Class for Pydantic Dynamic Model Generation""" - field: str field_alias: str field_type: Any @@ -32,12 +30,6 @@ class ModelDef(BaseModel): class PydanticModelGenerator: - """ - Takes in created classes and stubs them out in a way FastAPI/Pydantic is happy about: - source_data is a snapshot of the default values produced by the class - params are the names of the actual keys required by __init__ - """ - def __init__( self, model_name: str = None, @@ -81,10 +73,6 @@ class PydanticModelGenerator: field_exclude=fld["exclude"] if "exclude" in fld else False)) def generate_model(self): - """ - Creates a pydantic BaseModel - from the json and overrides provided at initialization - """ model_fields = { d.field: (d.field_type, Field(default=d.field_value, alias=d.field_alias, exclude=d.field_exclude)) for d in self._model_def } DynamicModel = create_model(self._model_name, **model_fields) DynamicModel.__config__.allow_population_by_field_name = True @@ -376,3 +364,8 @@ class ResNVML(BaseModel): # definition of http response load: dict = Field(title="Version") power: list = [] state: str = Field(title="State") + + +# compatibility items +StableDiffusionTxt2ImgProcessingAPI = ResTxt2Img +StableDiffusionImg2ImgProcessingAPI = ResImg2Img