refactor: log indentation via formatter

Replace manual indentation with a context-aware logging formatter.
pull/55/head
Bryce 2 years ago committed by Bryce Drennan
parent df3c752eb8
commit 7ae77faf07

@ -147,7 +147,7 @@ def imagine_image_files(
subpath, f"{basefilename}_[{image_type}].{output_file_extension}"
)
result.save(filepath, image_type=image_type)
logger.info(f" 🖼 [{image_type}] saved to: {filepath}")
logger.info(f"🖼 [{image_type}] saved to: {filepath}")
base_count += 1
del result
@ -181,12 +181,12 @@ def imagine(
precision
), fix_torch_nn_layer_norm(), fix_torch_group_norm():
for prompt in prompts:
logger.info(f"Generating 🖼 : {prompt.prompt_description()}")
with ImageLoggingContext(
prompt=prompt,
model=model,
img_callback=img_callback,
):
logger.info(f"Generating {prompt.prompt_description()}")
seed_everything(prompt.seed)
model.tile_mode(prompt.tile_mode)
@ -234,7 +234,7 @@ def imagine(
max_width=prompt.width,
)
except PIL.UnidentifiedImageError:
logger.warning(f" Could not load image: {prompt.init_image}")
logger.warning(f"Could not load image: {prompt.init_image}")
continue
init_image_t = pillow_img_to_torch_image(init_image)
@ -352,7 +352,7 @@ def imagine(
if add_caption:
caption = generate_caption(img)
logger.info(f" Generated caption: {caption}")
logger.info(f"Generated caption: {caption}")
safety_score = create_safety_score(
img,
@ -360,10 +360,10 @@ def imagine(
)
if not safety_score.is_filtered:
if prompt.fix_faces:
logger.info(" Fixing 😊 's in 🖼 using CodeFormer...")
logger.info("Fixing 😊 's in 🖼 using CodeFormer...")
img = enhance_faces(img, fidelity=prompt.fix_faces_fidelity)
if prompt.upscale:
logger.info(" Upscaling 🖼 using real-ESRGAN...")
logger.info("Upscaling 🖼 using real-ESRGAN...")
upscaled_img = upscale_image(img)
# put the newly generated patch back into the original, full size image

@ -67,7 +67,7 @@ def enhance_faces(img, fidelity=0):
num_det_faces = face_helper.get_face_landmarks_5(
only_center_face=False, resize=640, eye_dist_threshold=5
)
logger.info(f" Enhancing {num_det_faces} faces")
logger.info(f"Enhancing {num_det_faces} faces")
# align and warp each face
face_helper.align_warp_face()

@ -98,6 +98,14 @@ def conditioning_to_img(conditioning):
return ToPILImage()(conditioning)
class IndentingFormatter(logging.Formatter):
def format(self, record):
s = super().format(record)
if _CURRENT_LOGGING_CONTEXT is not None:
s = f" {s}"
return s
def configure_logging(level="INFO"):
fmt = "%(message)s"
if level == "DEBUG":
@ -107,7 +115,10 @@ def configure_logging(level="INFO"):
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"standard": {"format": fmt},
"standard": {
"format": fmt,
"class": "imaginairy.log_utils.IndentingFormatter",
},
},
"handlers": {
"default": {

@ -153,7 +153,7 @@ class ImaginePrompt:
def prompt_description(self):
return (
f'🖼 : "{self.prompt_text}" {self.width}x{self.height}px '
f'"{self.prompt_text}" {self.width}x{self.height}px '
f"seed:{self.seed} prompt-strength:{self.prompt_strength} steps:{self.steps} sampler-type:{self.sampler_type}"
)

Loading…
Cancel
Save