import gradio as gr import os import argparse from kohya_gui.class_gui_config import KohyaSSGUIConfig from kohya_gui.dreambooth_gui import dreambooth_tab from kohya_gui.finetune_gui import finetune_tab from kohya_gui.textual_inversion_gui import ti_tab from kohya_gui.utilities import utilities_tab from kohya_gui.lora_gui import lora_tab from kohya_gui.class_lora_tab import LoRATools from kohya_gui.custom_logging import setup_logging from kohya_gui.localization_ext import add_javascript def UI(**kwargs): add_javascript(kwargs.get("language")) css = "" headless = kwargs.get("headless", False) log.info(f"headless: {headless}") if os.path.exists("./assets/style.css"): with open(os.path.join("./assets/style.css"), "r", encoding="utf8") as file: log.debug("Load CSS...") css += file.read() + "\n" if os.path.exists("./.release"): with open(os.path.join("./.release"), "r", encoding="utf8") as file: release = file.read() if os.path.exists("./README.md"): with open(os.path.join("./README.md"), "r", encoding="utf8") as file: README = file.read() interface = gr.Blocks( css=css, title=f"Kohya_ss GUI {release}", theme=gr.themes.Default() ) config = KohyaSSGUIConfig(config_file_path=kwargs.get("config")) if config.is_config_loaded(): log.info(f"Loaded default GUI values from '{kwargs.get('config')}'...") use_shell_flag = True # if os.name == "posix": # use_shell_flag = True use_shell_flag = config.get("settings.use_shell", use_shell_flag) if kwargs.get("do_not_use_shell", False): use_shell_flag = False if use_shell_flag: log.info("Using shell=True when running external commands...") with interface: with gr.Tab("Dreambooth"): ( train_data_dir_input, reg_data_dir_input, output_dir_input, logging_dir_input, ) = dreambooth_tab( headless=headless, config=config, use_shell_flag=use_shell_flag ) with gr.Tab("LoRA"): lora_tab(headless=headless, config=config, use_shell_flag=use_shell_flag) with gr.Tab("Textual Inversion"): ti_tab(headless=headless, config=config, use_shell_flag=use_shell_flag) with gr.Tab("Finetuning"): finetune_tab( headless=headless, config=config, use_shell_flag=use_shell_flag ) with gr.Tab("Utilities"): utilities_tab( train_data_dir_input=train_data_dir_input, reg_data_dir_input=reg_data_dir_input, output_dir_input=output_dir_input, logging_dir_input=logging_dir_input, headless=headless, config=config, ) with gr.Tab("LoRA"): _ = LoRATools(headless=headless) with gr.Tab("About"): gr.Markdown(f"kohya_ss GUI release {release}") with gr.Tab("README"): gr.Markdown(README) htmlStr = f"""