Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom save directory for output images #1582

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,6 @@ apps/stable_diffusion/web/models/

# Stencil annotators.
stencil_annotator/

# macOS related
.DS_Store
4 changes: 2 additions & 2 deletions apps/stable_diffusion/src/utils/stable_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion apps/stable_diffusion/src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)


Expand Down
10 changes: 7 additions & 3 deletions apps/stable_diffusion/web/ui/img2img_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions apps/stable_diffusion/web/ui/inpaint_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions apps/stable_diffusion/web/ui/outpaint_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions apps/stable_diffusion/web/ui/txt2img_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions apps/stable_diffusion/web/ui/upscaler_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down