diff --git a/.gitignore b/.gitignore index eeb217e2b6..122ea9c65b 100644 --- a/.gitignore +++ b/.gitignore @@ -189,3 +189,6 @@ apps/stable_diffusion/web/models/ # Stencil annotators. stencil_annotator/ + +# macOS related +.DS_Store diff --git a/apps/stable_diffusion/src/utils/stable_args.py b/apps/stable_diffusion/src/utils/stable_args.py index df75e16abb..704b8dd428 100644 --- a/apps/stable_diffusion/src/utils/stable_args.py +++ b/apps/stable_diffusion/src/utils/stable_args.py @@ -312,8 +312,8 @@ def is_valid_file(arg): p.add_argument( "--output_dir", type=str, - default=None, - help="Directory path to save the output images and json.", + default=str(os.path.join(os.getcwd(), "generated_imgs")), + help="Directory path to save the output images and json", ) p.add_argument( diff --git a/apps/stable_diffusion/src/utils/utils.py b/apps/stable_diffusion/src/utils/utils.py index de3c5e324d..745bacd701 100644 --- a/apps/stable_diffusion/src/utils/utils.py +++ b/apps/stable_diffusion/src/utils/utils.py @@ -761,7 +761,7 @@ def clear_all(): def get_generated_imgs_path() -> Path: return Path( - args.output_dir if args.output_dir else Path.cwd(), "generated_imgs" + args.output_dir if args.output_dir else Path(Path.cwd(), "generated_imgs") ) diff --git a/apps/stable_diffusion/web/ui/img2img_ui.py b/apps/stable_diffusion/web/ui/img2img_ui.py index 48f54ffb4b..91a4a8f67d 100644 --- a/apps/stable_diffusion/web/ui/img2img_ui.py +++ b/apps/stable_diffusion/web/ui/img2img_ui.py @@ -66,6 +66,7 @@ def img2img_inf( lora_weights: str, lora_hf_id: str, ondemand: bool, + std_output: str = args.output_dir, ): from apps.stable_diffusion.web.ui.utils import ( get_custom_model_pathfile, @@ -170,6 +171,7 @@ def img2img_inf( args.iree_vulkan_target_triple = init_iree_vulkan_target_triple args.use_tuned = init_use_tuned args.import_mlir = init_import_mlir + args.output_dir = str(std_output) set_init_device_flags() model_id = ( args.hf_model_id @@ -635,11 +637,12 @@ def create_canvas(w, h): elem_id="gallery", ).style(columns=[2], object_fit="contain") std_output = gr.Textbox( - value=f"Images will be saved at " - f"{get_generated_imgs_path()}", - lines=1, + lines=2, elem_id="std_output", + label="Image Save Location", show_label=False, + interactive=True, + placeholder=f"Images will be saved at {get_generated_imgs_path()} by default.\nTo save the images in a custom directory, type the path to an already created directory to save the images in.", ) img2img_status = gr.Textbox(visible=False) with gr.Row(): @@ -678,6 +681,7 @@ def create_canvas(w, h): lora_weights, lora_hf_id, ondemand, + std_output, ], outputs=[img2img_gallery, std_output, img2img_status], show_progress="minimal" if args.progress_bar else "none", diff --git a/apps/stable_diffusion/web/ui/inpaint_ui.py b/apps/stable_diffusion/web/ui/inpaint_ui.py index 39e197b6d9..b2bf50539e 100644 --- a/apps/stable_diffusion/web/ui/inpaint_ui.py +++ b/apps/stable_diffusion/web/ui/inpaint_ui.py @@ -64,6 +64,7 @@ def inpaint_inf( lora_weights: str, lora_hf_id: str, ondemand: bool, + std_output: str = args.output_dir, ): from apps.stable_diffusion.web.ui.utils import ( get_custom_model_pathfile, @@ -146,6 +147,7 @@ def inpaint_inf( args.iree_vulkan_target_triple = init_iree_vulkan_target_triple args.use_tuned = init_use_tuned args.import_mlir = init_import_mlir + args.output_dir = str(std_output) set_init_device_flags() model_id = ( args.hf_model_id @@ -535,11 +537,12 @@ def inpaint_api( elem_id="gallery", ).style(columns=[2], object_fit="contain") std_output = gr.Textbox( - value=f"Images will be saved at " - f"{get_generated_imgs_path()}", - lines=1, + lines=2, elem_id="std_output", + label="Image Save Location", show_label=False, + interactive=True, + placeholder=f"Images will be saved at {get_generated_imgs_path()} by default.\nTo save the images in a custom directory, type the path to an already created directory to save the images in.", ) inpaint_status = gr.Textbox(visible=False) @@ -579,6 +582,7 @@ def inpaint_api( lora_weights, lora_hf_id, ondemand, + std_output, ], outputs=[inpaint_gallery, std_output, inpaint_status], show_progress="minimal" if args.progress_bar else "none", diff --git a/apps/stable_diffusion/web/ui/outpaint_ui.py b/apps/stable_diffusion/web/ui/outpaint_ui.py index 362103259a..305930fc61 100644 --- a/apps/stable_diffusion/web/ui/outpaint_ui.py +++ b/apps/stable_diffusion/web/ui/outpaint_ui.py @@ -64,6 +64,7 @@ def outpaint_inf( lora_weights: str, lora_hf_id: str, ondemand: bool, + std_output: str = args.output_dir, ): from apps.stable_diffusion.web.ui.utils import ( get_custom_model_pathfile, @@ -145,6 +146,7 @@ def outpaint_inf( args.iree_vulkan_target_triple = init_iree_vulkan_target_triple args.use_tuned = init_use_tuned args.import_mlir = init_import_mlir + args.output_dir = str(std_output) set_init_device_flags() model_id = ( args.hf_model_id @@ -562,11 +564,12 @@ def outpaint_api( elem_id="gallery", ).style(columns=[2], object_fit="contain") std_output = gr.Textbox( - value=f"Images will be saved at " - f"{get_generated_imgs_path()}", - lines=1, + lines=2, elem_id="std_output", + label="Image Save Location", show_label=False, + interactive=True, + placeholder=f"Images will be saved at {get_generated_imgs_path()} by default.\nTo save the images in a custom directory, type the path to an already created directory to save the images in.", ) outpaint_status = gr.Textbox(visible=False) with gr.Row(): @@ -606,6 +609,7 @@ def outpaint_api( lora_weights, lora_hf_id, ondemand, + std_output, ], outputs=[outpaint_gallery, std_output, outpaint_status], show_progress="minimal" if args.progress_bar else "none", diff --git a/apps/stable_diffusion/web/ui/txt2img_ui.py b/apps/stable_diffusion/web/ui/txt2img_ui.py index 1348bc781b..3b89964b66 100644 --- a/apps/stable_diffusion/web/ui/txt2img_ui.py +++ b/apps/stable_diffusion/web/ui/txt2img_ui.py @@ -61,6 +61,7 @@ def txt2img_inf( lora_weights: str, lora_hf_id: str, ondemand: bool, + std_output: str = args.output_dir, ): from apps.stable_diffusion.web.ui.utils import ( get_custom_model_pathfile, @@ -143,6 +144,7 @@ def txt2img_inf( args.use_tuned = init_use_tuned args.import_mlir = init_import_mlir args.img_path = None + args.output_dir = str(std_output) set_init_device_flags() model_id = ( args.hf_model_id @@ -510,11 +512,12 @@ def txt2img_api( elem_id="gallery", ).style(columns=[2], object_fit="contain") std_output = gr.Textbox( - value=f"Images will be saved at " - f"{get_generated_imgs_path()}", - lines=1, + lines=2, elem_id="std_output", + label="Image Save Location", show_label=False, + interactive=True, + placeholder=f"Images will be saved at {get_generated_imgs_path()} by default.\nTo save the images in a custom directory, type the path to an already created directory to save the images in.", ) txt2img_status = gr.Textbox(visible=False) with gr.Row(): @@ -551,6 +554,7 @@ def txt2img_api( lora_weights, lora_hf_id, ondemand, + std_output, ], outputs=[txt2img_gallery, std_output, txt2img_status], show_progress="minimal" if args.progress_bar else "none", diff --git a/apps/stable_diffusion/web/ui/upscaler_ui.py b/apps/stable_diffusion/web/ui/upscaler_ui.py index 756e3cd9c2..004434a6de 100644 --- a/apps/stable_diffusion/web/ui/upscaler_ui.py +++ b/apps/stable_diffusion/web/ui/upscaler_ui.py @@ -57,6 +57,7 @@ def upscaler_inf( lora_weights: str, lora_hf_id: str, ondemand: bool, + std_output: str = args.output_dir ): from apps.stable_diffusion.web.ui.utils import ( get_custom_model_pathfile, @@ -140,6 +141,7 @@ def upscaler_inf( args.iree_vulkan_target_triple = init_iree_vulkan_target_triple args.use_tuned = init_use_tuned args.import_mlir = init_import_mlir + args.output_dir = std_output set_init_device_flags() model_id = ( args.hf_model_id @@ -554,11 +556,12 @@ def upscaler_api( elem_id="gallery", ).style(columns=[2], object_fit="contain") std_output = gr.Textbox( - value=f"Images will be saved at " - f"{get_generated_imgs_path()}", - lines=1, + lines=2, elem_id="std_output", + label="Image Save Location", show_label=False, + interactive=True, + placeholder=f"Images will be saved at {get_generated_imgs_path()} by default.\nTo save the images in a custom directory, type the path to an already created directory to save the images in.", ) upscaler_status = gr.Textbox(visible=False) @@ -595,6 +598,7 @@ def upscaler_api( lora_weights, lora_hf_id, ondemand, + std_output, ], outputs=[upscaler_gallery, std_output, upscaler_status], show_progress="minimal" if args.progress_bar else "none",