Merge branch 'main' into lstein/bugfix/compel

This commit is contained in:
Eugene Brodsky 2023-05-14 14:43:18 -04:00 committed by GitHub
commit c8a98a9a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 53 deletions

View File

@ -2,34 +2,37 @@
"""invokeai.util.logging """invokeai.util.logging
Logging class for InvokeAI that produces console messages that follow Logging class for InvokeAI that produces console messages
the conventions established in InvokeAI 1.X through 2.X.
Usage:
One way to use it:
from invokeai.backend.util.logging import InvokeAILogger from invokeai.backend.util.logging import InvokeAILogger
logger = InvokeAILogger.getLogger(__name__) logger = InvokeAILogger.getLogger(name='InvokeAI') // Initialization
logger.critical('this is critical') (or)
logger.error('this is an error') logger = InvokeAILogger.getLogger(__name__) // To use the filename
logger.warning('this is a warning')
logger.info('this is info') logger.critical('this is critical') // Critical Message
logger.debug('this is debugging') logger.error('this is an error') // Error Message
logger.warning('this is a warning') // Warning Message
logger.info('this is info') // Info Message
logger.debug('this is debugging') // Debug Message
Console messages: Console messages:
### this is critical [12-05-2023 20]::[InvokeAI]::CRITICAL --> This is an info message [In Bold Red]
*** this is an error *** [12-05-2023 20]::[InvokeAI]::ERROR --> This is an info message [In Red]
** this is a warning [12-05-2023 20]::[InvokeAI]::WARNING --> This is an info message [In Yellow]
>> this is info [12-05-2023 20]::[InvokeAI]::INFO --> This is an info message [In Grey]
| this is debugging [12-05-2023 20]::[InvokeAI]::DEBUG --> This is an info message [In Grey]
Another way: Alternate Method (in this case the logger name will be set to InvokeAI):
import invokeai.backend.util.logging as ialog import invokeai.backend.util.logging as IAILogger
ialogger.debug('this is a debugging message') IAILogger.debug('this is a debugging message')
""" """
import logging import logging
# module level functions # module level functions
def debug(msg, *args, **kwargs): def debug(msg, *args, **kwargs):
InvokeAILogger.getLogger().debug(msg, *args, **kwargs) InvokeAILogger.getLogger().debug(msg, *args, **kwargs)
@ -42,7 +45,7 @@ def warning(msg, *args, **kwargs):
def error(msg, *args, **kwargs): def error(msg, *args, **kwargs):
InvokeAILogger.getLogger().error(msg, *args, **kwargs) InvokeAILogger.getLogger().error(msg, *args, **kwargs)
def critical(msg, *args, **kwargs): def critical(msg, *args, **kwargs):
InvokeAILogger.getLogger().critical(msg, *args, **kwargs) InvokeAILogger.getLogger().critical(msg, *args, **kwargs)
@ -55,49 +58,47 @@ def disable(level=logging.CRITICAL):
def basicConfig(**kwargs): def basicConfig(**kwargs):
InvokeAILogger.getLogger().basicConfig(**kwargs) InvokeAILogger.getLogger().basicConfig(**kwargs)
def getLogger(name: str=None)->logging.Logger: def getLogger(name: str = None) -> logging.Logger:
return InvokeAILogger.getLogger(name) return InvokeAILogger.getLogger(name)
class InvokeAILogFormatter(logging.Formatter): class InvokeAILogFormatter(logging.Formatter):
''' '''
Repurposed from: Custom Formatting for the InvokeAI Logger
https://stackoverflow.com/questions/14844970/modifying-logging-message-format-based-on-message-logging-level-in-python3
''' '''
crit_fmt = "### %(msg)s"
err_fmt = "*** %(msg)s"
warn_fmt = "** %(msg)s"
info_fmt = ">> %(msg)s"
dbg_fmt = " | %(msg)s"
def __init__(self): # Color Codes
super().__init__(fmt="%(levelno)d: %(msg)s", datefmt=None, style='%') grey = "\x1b[38;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
cyan = "\x1b[36;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
# Log Format
format = "[%(asctime)s]::[%(name)s]::%(levelname)s --> %(message)s"
## More Formatting Options: %(pathname)s, %(filename)s, %(module)s, %(lineno)d
# Format Map
FORMATS = {
logging.DEBUG: cyan + format + reset,
logging.INFO: grey + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset
}
def format(self, record): def format(self, record):
# Remember the format used when the logging module log_fmt = self.FORMATS.get(record.levelno)
# was installed (in the event that this formatter is formatter = logging.Formatter(log_fmt, datefmt="%d-%m-%Y %H:%M:%S")
# used with the vanilla logging module. return formatter.format(record)
format_orig = self._style._fmt
if record.levelno == logging.DEBUG:
self._style._fmt = InvokeAILogFormatter.dbg_fmt
if record.levelno == logging.INFO:
self._style._fmt = InvokeAILogFormatter.info_fmt
if record.levelno == logging.WARNING:
self._style._fmt = InvokeAILogFormatter.warn_fmt
if record.levelno == logging.ERROR:
self._style._fmt = InvokeAILogFormatter.err_fmt
if record.levelno == logging.CRITICAL:
self._style._fmt = InvokeAILogFormatter.crit_fmt
# parent class does the work
result = super().format(record)
self._style._fmt = format_orig
return result
class InvokeAILogger(object): class InvokeAILogger(object):
loggers = dict() loggers = dict()
@classmethod @classmethod
def getLogger(self, name:str='invokeai')->logging.Logger: def getLogger(self, name: str = 'InvokeAI') -> logging.Logger:
if name not in self.loggers: if name not in self.loggers:
logger = logging.getLogger(name) logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)

View File

@ -30,9 +30,14 @@ const DEFAULT_CONFIG = {};
interface Props { interface Props {
config?: PartialAppConfig; config?: PartialAppConfig;
headerComponent?: ReactNode; headerComponent?: ReactNode;
setIsReady?: (isReady: boolean) => void;
} }
const App = ({ config = DEFAULT_CONFIG, headerComponent }: Props) => { const App = ({
config = DEFAULT_CONFIG,
headerComponent,
setIsReady,
}: Props) => {
useToastWatcher(); useToastWatcher();
useGlobalHotkeys(); useGlobalHotkeys();
@ -61,6 +66,16 @@ const App = ({ config = DEFAULT_CONFIG, headerComponent }: Props) => {
setLoadingOverridden(true); setLoadingOverridden(true);
}, []); }, []);
useEffect(() => {
if (isApplicationReady && setIsReady) {
setIsReady(true);
}
return () => {
setIsReady && setIsReady(false);
};
}, [isApplicationReady, setIsReady]);
return ( return (
<Grid w="100vw" h="100vh" position="relative" overflow="hidden"> <Grid w="100vw" h="100vh" position="relative" overflow="hidden">
{isLightboxEnabled && <Lightbox />} {isLightboxEnabled && <Lightbox />}

View File

@ -24,9 +24,16 @@ interface Props extends PropsWithChildren {
token?: string; token?: string;
config?: PartialAppConfig; config?: PartialAppConfig;
headerComponent?: ReactNode; headerComponent?: ReactNode;
setIsReady?: (isReady: boolean) => void;
} }
const InvokeAIUI = ({ apiUrl, token, config, headerComponent }: Props) => { const InvokeAIUI = ({
apiUrl,
token,
config,
headerComponent,
setIsReady,
}: Props) => {
useEffect(() => { useEffect(() => {
// configure API client token // configure API client token
if (token) { if (token) {
@ -55,7 +62,11 @@ const InvokeAIUI = ({ apiUrl, token, config, headerComponent }: Props) => {
<Provider store={store}> <Provider store={store}>
<React.Suspense fallback={<Loading />}> <React.Suspense fallback={<Loading />}>
<ThemeLocaleProvider> <ThemeLocaleProvider>
<App config={config} headerComponent={headerComponent} /> <App
config={config}
headerComponent={headerComponent}
setIsReady={setIsReady}
/>
</ThemeLocaleProvider> </ThemeLocaleProvider>
</React.Suspense> </React.Suspense>
</Provider> </Provider>

View File

@ -17,8 +17,17 @@ const InvokeAILogoComponent = () => {
h="32px" h="32px"
minW="32px" minW="32px"
minH="32px" minH="32px"
userSelect="none"
/> />
<Flex gap={3} display={{ base: 'inherit', sm: 'none', md: 'inherit' }}> <Flex
gap={3}
display={{
base: 'inherit',
sm: 'none',
md: 'inherit',
userSelect = 'none',
}}
>
<Text fontSize="xl"> <Text fontSize="xl">
invoke <strong>ai</strong> invoke <strong>ai</strong>
</Text> </Text>

View File

@ -2,6 +2,9 @@
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
import logging
logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
import os import os
import sys import sys