From 97f237360b83df2d1b7daea4eaac7860328a49b9 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Fri, 27 Sep 2024 16:25:34 +0200 Subject: [PATCH] Update lollms_diffusers.py --- .../tti/diffusers/lollms_diffusers.py | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lollms/services/tti/diffusers/lollms_diffusers.py b/lollms/services/tti/diffusers/lollms_diffusers.py index e291f2c..968e111 100644 --- a/lollms/services/tti/diffusers/lollms_diffusers.py +++ b/lollms/services/tti/diffusers/lollms_diffusers.py @@ -238,13 +238,31 @@ class LollmsDiffusers(LollmsTTI): self.model.scheduler = sc width = adjust_dimensions(int(width)) height = adjust_dimensions(int(height)) + + + def process_output_path(output_path, self_output_dir): + if output_path is None: + output_path = Path(self_output_dir) + fn = find_next_available_filename(output_path, "diff_img_") + else: + output_path = Path(output_path) + if output_path.is_file(): + fn = output_path + elif output_path.is_dir(): + fn = find_next_available_filename(output_path, "diff_img_") + else: + # If the path doesn't exist, assume it's intended to be a file + fn = output_path + + return fn + + + # Usage in the original context if output_path is None: output_path = self.output_dir - output_path = Path(output_path) - fn = find_next_available_filename(output_path,"diff_img_") - else: - output_path = Path(output_path) - fn = output_path + + fn = process_output_path(output_path, self.output_dir) + if seed!=-1: generator = torch.Generator("cuda").manual_seed(seed) image = self.model(positive_prompt, negative_prompt=negative_prompt, height=height, width=width, guidance_scale=scale, num_inference_steps=steps, generator=generator).images[0]