diff --git a/README.md b/README.md index 672e137..0ac86bd 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ ### 0.6.1 BETA3 - 'Force Upscale' option inside the 'Upscale' tab: ReActor will run the Upscaler even if there's no face is detected (FR https://github.com/Gourieff/sd-webui-reactor/issues/116) +- ReActor shows filenames of source images in-process when the multiple images mode or the folder mode (random as well) is selected ### 0.6.1 BETA2 diff --git a/README_RU.md b/README_RU.md index f595cc6..36cef74 100644 --- a/README_RU.md +++ b/README_RU.md @@ -42,6 +42,7 @@ ### 0.6.1 BETA3 - Опция 'Force Upscale' внутри вкладки 'Upscale': апскейл выполнится, даже если не было обнаружено ни одного лица (FR https://github.com/Gourieff/sd-webui-reactor/issues/116) +- Отображение имён файлов используемых изображений, когда выбрано несколько изображений или папка (а также режим случайного изображения) ### 0.6.1 BETA2 diff --git a/scripts/reactor_faceswap.py b/scripts/reactor_faceswap.py index cb4b9dd..604884a 100644 --- a/scripts/reactor_faceswap.py +++ b/scripts/reactor_faceswap.py @@ -238,7 +238,11 @@ class FaceSwapScript(scripts.Script): if ((self.source is not None or self.source_imgs is not None) and self.select_source == 0) or ((self.face_model is not None and self.face_model != "None") and self.select_source == 1) or ((self.source_folder is not None and self.source_folder != "") and self.select_source == 2): logger.debug("*** Log patch") apply_logging_patch(console_logging_level) + if isinstance(p, StableDiffusionProcessingImg2Img) and self.swap_in_source: + + logger.debug("*** Check process") + logger.status("Working: source face index %s, target face index %s", self.source_faces_index, self.faces_index) for i in range(len(p.init_images)): @@ -279,7 +283,7 @@ class FaceSwapScript(scripts.Script): def postprocess(self, p: StableDiffusionProcessing, processed: Processed, *args): if self.enable: - logger.debug("*** Check postprocess") + logger.debug("*** Check postprocess - before IF") reset_messaged() if check_process_halt(): @@ -287,6 +291,8 @@ class FaceSwapScript(scripts.Script): if self.save_original or ((self.select_source == 2 and self.source_folder is not None and self.source_folder != "") or (self.select_source == 0 and self.source_imgs is not None and self.source is None)): + logger.debug("*** Check postprocess - after IF") + postprocess_run: bool = True orig_images : List[Image.Image] = processed.images[processed.index_of_first_image:] @@ -373,6 +379,21 @@ class FaceSwapScript(scripts.Script): processed.images = result_images # processed.infotexts = result_info + + elif self.select_source == 0 and self.source is not None and self.source_imgs is not None: + + logger.debug("*** Check postprocess - after ELIF") + + if self.result is not None: + orig_infotexts : List[str] = processed.infotexts[processed.index_of_first_image:] + processed.images = [self.result] + try: + img_path = save_image(self.result, p.outpath_samples, "", p.all_seeds[0], p.all_prompts[0], "png", info=orig_infotexts[0], p=p, suffix="") + except: + logger.error("Cannot save a result image - please, check SD WebUI Settings (Saving and Paths)") + else: + logger.error("Cannot create a result image") + def postprocess_batch(self, p, *args, **kwargs): if self.enable and not self.save_original: @@ -392,7 +413,7 @@ class FaceSwapScript(scripts.Script): return # if (self.source is not None and self.select_source == 0) or ((self.face_model is not None and self.face_model != "None") and self.select_source == 1): - logger.status("Working: source face index %s, target face index %s", self.source_faces_index, self.faces_index) + logger.status("! Working: source face index %s, target face index %s", self.source_faces_index, self.faces_index) image: Image.Image = script_pp.image result, output, swapped = swap_face( self.source, @@ -413,6 +434,7 @@ class FaceSwapScript(scripts.Script): source_imgs = None, random_image = False, ) + self.result = result try: pp = scripts_postprocessing.PostprocessedImage(result) pp.info = {} @@ -575,6 +597,9 @@ class FaceSwapScriptExtras(scripts_postprocessing.ScriptPostprocessing): logger.debug("We're here: process() 2") + if self.source is not None and self.select_source == 0: + self.source_imgs = None + apply_logging_patch(self.console_logging_level) logger.status("Working: source face index %s, target face index %s", self.source_faces_index, self.faces_index) # if self.select_source != 2: diff --git a/scripts/reactor_helpers.py b/scripts/reactor_helpers.py index c3384bd..6c31dfe 100644 --- a/scripts/reactor_helpers.py +++ b/scripts/reactor_helpers.py @@ -209,14 +209,27 @@ def get_model_names(get_models): return names def get_images_from_folder(path: str): - images_path = os.path.join(path, "*") - images = glob.glob(images_path) - return [Image.open(x) for x in images if x.endswith(('jpg', 'png', 'jpeg', 'webp', 'bmp'))] + files_path = os.path.join(path, "*") + files = glob.glob(files_path) + images = [] + images_names = [] + for x in files: + if x.endswith(('jpg', 'png', 'jpeg', 'webp', 'bmp')): + images.append(Image.open(x)) + images_names.append(os.path.basename(x)) + return images,images_names + # return [Image.open(x) for x in images if x.endswith(('jpg', 'png', 'jpeg', 'webp', 'bmp'))],[os.path.basename(x) for x in images if x.endswith(('jpg', 'png', 'jpeg', 'webp', 'bmp'))] def get_random_image_from_folder(path: str): - images = get_images_from_folder(path) + images,names = get_images_from_folder(path) random_image_index = random.randint(0, len(images) - 1) - return [images[random_image_index]] + return [images[random_image_index]],[names[random_image_index]] def get_images_from_list(imgs: List): - return [Image.open(os.path.abspath(x.name)) for x in imgs] + images = [] + images_names = [] + for x in imgs: + images.append(Image.open(os.path.abspath(x.name))) + images_names.append(os.path.basename(x.name)) + return images,images_names + # return [Image.open(os.path.abspath(x.name)) for x in imgs],[os.path.basename(x.name) for x in imgs] diff --git a/scripts/reactor_swapper.py b/scripts/reactor_swapper.py index 9a9641f..6d34648 100644 --- a/scripts/reactor_swapper.py +++ b/scripts/reactor_swapper.py @@ -380,10 +380,10 @@ def swap_face( result = [] if random_image and select_source == 2: - source_images = get_random_image_from_folder(source_folder) - logger.status("Processing with Random Image from the folder") + source_images,source_images_names = get_random_image_from_folder(source_folder) + logger.status(f"Processing with Random Image from the folder: {source_images_names[0]}") else: - source_images = get_images_from_folder(source_folder) if select_source == 2 else get_images_from_list(source_imgs) + source_images,source_images_names = get_images_from_folder(source_folder) if select_source == 2 else get_images_from_list(source_imgs) if len(source_images) > 0: source_img_ff = [] @@ -412,15 +412,15 @@ def swap_face( logger.info("(Image %s) Source Image the Same? %s", i, source_image_same) if len(SOURCE_FACES_LIST) == 0: - logger.status(f"Analyzing Source Image {i}...") + logger.status(f"Analyzing Source Image {i}: {source_images_names[i]}...") source_faces = analyze_faces(source_image) SOURCE_FACES_LIST = [source_faces] elif len(SOURCE_FACES_LIST) == i and not source_image_same: - logger.status(f"Analyzing Source Image {i}...") + logger.status(f"Analyzing Source Image {i}: {source_images_names[i]}...") source_faces = analyze_faces(source_image) SOURCE_FACES_LIST.append(source_faces) elif len(SOURCE_FACES_LIST) != i and not source_image_same: - logger.status(f"Analyzing Source Image {i}...") + logger.status(f"Analyzing Source Image {i}: {source_images_names[i]}...") source_faces = analyze_faces(source_image) SOURCE_FACES_LIST[i] = source_faces elif source_image_same: