2023-07-20 12:33:01 +00:00
|
|
|
from enum import Enum
|
|
|
|
from fastapi import Body
|
2023-07-08 09:31:17 +00:00
|
|
|
from fastapi.routing import APIRouter
|
2023-07-13 05:20:20 +00:00
|
|
|
from pydantic import BaseModel, Field
|
2023-07-08 09:31:17 +00:00
|
|
|
|
2023-07-13 05:20:20 +00:00
|
|
|
from invokeai.backend.image_util.patchmatch import PatchMatch
|
2023-07-08 09:31:17 +00:00
|
|
|
from invokeai.version import __version__
|
|
|
|
|
2023-07-20 12:33:01 +00:00
|
|
|
from ..dependencies import ApiDependencies
|
|
|
|
from invokeai.backend.util.logging import logging
|
|
|
|
|
|
|
|
class LogLevel(int, Enum):
|
|
|
|
NotSet = logging.NOTSET
|
|
|
|
Debug = logging.DEBUG
|
|
|
|
Info = logging.INFO
|
|
|
|
Warning = logging.WARNING
|
|
|
|
Error = logging.ERROR
|
|
|
|
Critical = logging.CRITICAL
|
|
|
|
|
2023-07-13 05:20:20 +00:00
|
|
|
app_router = APIRouter(prefix="/v1/app", tags=["app"])
|
2023-07-08 09:31:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AppVersion(BaseModel):
|
|
|
|
"""App Version Response"""
|
2023-07-13 05:20:20 +00:00
|
|
|
|
|
|
|
version: str = Field(description="App version")
|
|
|
|
|
2023-07-08 09:31:17 +00:00
|
|
|
|
2023-07-12 15:54:42 +00:00
|
|
|
class AppConfig(BaseModel):
|
|
|
|
"""App Config Response"""
|
2023-07-13 05:20:20 +00:00
|
|
|
|
|
|
|
infill_methods: list[str] = Field(description="List of available infill methods")
|
2023-07-12 15:54:42 +00:00
|
|
|
|
2023-07-08 09:31:17 +00:00
|
|
|
|
2023-07-13 05:20:20 +00:00
|
|
|
@app_router.get(
|
|
|
|
"/version", operation_id="app_version", status_code=200, response_model=AppVersion
|
|
|
|
)
|
2023-07-08 09:31:17 +00:00
|
|
|
async def get_version() -> AppVersion:
|
|
|
|
return AppVersion(version=__version__)
|
2023-07-12 15:54:42 +00:00
|
|
|
|
2023-07-13 05:20:20 +00:00
|
|
|
|
|
|
|
@app_router.get(
|
|
|
|
"/config", operation_id="get_config", status_code=200, response_model=AppConfig
|
|
|
|
)
|
2023-07-12 15:54:42 +00:00
|
|
|
async def get_config() -> AppConfig:
|
2023-07-13 05:20:20 +00:00
|
|
|
infill_methods = ['tile']
|
|
|
|
if PatchMatch.patchmatch_available():
|
|
|
|
infill_methods.append('patchmatch')
|
|
|
|
return AppConfig(infill_methods=infill_methods)
|
2023-07-20 12:33:01 +00:00
|
|
|
|
|
|
|
@app_router.get(
|
|
|
|
"/logging",
|
|
|
|
operation_id="get_log_level",
|
|
|
|
responses={200: {"description" : "The operation was successful"}},
|
|
|
|
response_model = LogLevel,
|
|
|
|
)
|
|
|
|
async def get_log_level(
|
|
|
|
) -> LogLevel:
|
|
|
|
"""Returns the log level"""
|
|
|
|
return LogLevel(ApiDependencies.invoker.services.logger.level)
|
|
|
|
|
|
|
|
@app_router.post(
|
|
|
|
"/logging",
|
|
|
|
operation_id="set_log_level",
|
|
|
|
responses={200: {"description" : "The operation was successful"}},
|
|
|
|
response_model = LogLevel,
|
|
|
|
)
|
|
|
|
async def set_log_level(
|
|
|
|
level: LogLevel = Body(description="New log verbosity level"),
|
|
|
|
) -> LogLevel:
|
|
|
|
"""Sets the log verbosity level"""
|
|
|
|
ApiDependencies.invoker.services.logger.setLevel(level)
|
|
|
|
return LogLevel(ApiDependencies.invoker.services.logger.level)
|