add api compatibility layer for civitai

This commit is contained in:
Vladimir Mandic
2024-01-30 16:19:03 -05:00
parent d0ff929fd2
commit 8f1f538bc9
2 changed files with 11 additions and 15 deletions
+6 -3
View File
@@ -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
+5 -12
View File
@@ -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