mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
refactor imports
This commit is contained in:
+15
-24
@@ -36,6 +36,12 @@ if not hasattr(BaseModel, "__config__"):
|
||||
BaseModel.__config__ = DummyConfig
|
||||
|
||||
|
||||
class PydanticConfig:
|
||||
arbitrary_types_allowed = True
|
||||
orm_mode = True
|
||||
allow_population_by_field_name = True
|
||||
|
||||
|
||||
def underscore(name: str) -> str: # Convert CamelCase or PascalCase string to underscore_case (snake_case).
|
||||
# use instead of inflection.underscore
|
||||
s1 = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name)
|
||||
@@ -92,11 +98,7 @@ class PydanticModelGenerator:
|
||||
if PYDANTIC_V2:
|
||||
config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True, populate_by_name=True)
|
||||
else:
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
orm_mode = True
|
||||
allow_population_by_field_name = True
|
||||
config = Config
|
||||
config = PydanticConfig
|
||||
DynamicModel = create_model(self._model_name, __config__=config, **model_fields)
|
||||
return DynamicModel
|
||||
|
||||
@@ -405,14 +407,10 @@ for key, metadata in shared.opts.data_labels.items():
|
||||
fields.update({key: (Optional[optType], Field())})
|
||||
|
||||
if PYDANTIC_V2:
|
||||
config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True, populate_by_name=True)
|
||||
pydantic_config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True, populate_by_name=True)
|
||||
else:
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
orm_mode = True
|
||||
allow_population_by_field_name = True
|
||||
config = Config
|
||||
OptionsModel = create_model("Options", __config__=config, **fields)
|
||||
pydantic_config = PydanticConfig
|
||||
OptionsModel = create_model("Options", __config__=pydantic_config, **fields)
|
||||
|
||||
flags = {}
|
||||
_options = vars(shared.parser)['_option_string_actions']
|
||||
@@ -425,14 +423,10 @@ for key in _options:
|
||||
flags.update({flag.dest: (_type, Field(default=flag.default, description=flag.help))})
|
||||
|
||||
if PYDANTIC_V2:
|
||||
config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True, populate_by_name=True)
|
||||
pydantic_config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True, populate_by_name=True)
|
||||
else:
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
orm_mode = True
|
||||
allow_population_by_field_name = True
|
||||
config = Config
|
||||
FlagsModel = create_model("Flags", __config__=config, **flags)
|
||||
pydantic_config = PydanticConfig
|
||||
FlagsModel = create_model("Flags", __config__=pydantic_config, **flags)
|
||||
|
||||
class ResEmbeddings(BaseModel):
|
||||
loaded: list = Field(default=None, title="loaded", description="List of loaded embeddings")
|
||||
@@ -499,12 +493,9 @@ def create_model_from_signature(func: Callable, model_name: str, base_model: typ
|
||||
if PYDANTIC_V2:
|
||||
config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True, populate_by_name=True, extra='allow' if varkw else 'ignore')
|
||||
else:
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
orm_mode = True
|
||||
allow_population_by_field_name = True
|
||||
class CustomConfig(PydanticConfig):
|
||||
extra = 'allow' if varkw else 'ignore'
|
||||
config = Config
|
||||
config = CustomConfig
|
||||
|
||||
model = create_model(
|
||||
model_name,
|
||||
|
||||
@@ -4,10 +4,14 @@ from typing import Any
|
||||
from fastapi import Request, Depends
|
||||
from fastapi.exceptions import HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
import installer
|
||||
from modules import shared
|
||||
from modules.logger import log
|
||||
from modules.api import models, helpers
|
||||
|
||||
def _get_version():
|
||||
return installer.get_version()
|
||||
|
||||
|
||||
def post_shutdown():
|
||||
log.info('Shutdown request received')
|
||||
@@ -43,7 +47,7 @@ def get_js(request: Request):
|
||||
def get_motd():
|
||||
import requests
|
||||
motd = ''
|
||||
ver = shared.get_version()
|
||||
ver = _get_version()
|
||||
if ver.get('updated', None) is not None:
|
||||
motd = f"version <b>{ver['commit']} {ver['updated']}</b> <span style='color: var(--primary-500)'>{ver['url'].split('/')[-1]}</span><br>" # pylint: disable=use-maxsplit-arg
|
||||
if shared.opts.motd:
|
||||
@@ -60,7 +64,7 @@ def get_motd():
|
||||
return motd
|
||||
|
||||
def get_version():
|
||||
return shared.get_version()
|
||||
return _get_version()
|
||||
|
||||
def get_platform():
|
||||
from installer import get_platform as installer_get_platform
|
||||
|
||||
Reference in New Issue
Block a user