MonsterMMORPG commited on
Commit
2c5d2ff
1 Parent(s): 0b93869

Upload kohya_gui.py

Browse files
Files changed (1) hide show
  1. kohya_gui.py +145 -0
kohya_gui.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import argparse
4
+ from dreambooth_gui import dreambooth_tab
5
+ from finetune_gui import finetune_tab
6
+ from textual_inversion_gui import ti_tab
7
+ from library.utilities import utilities_tab
8
+ from lora_gui import lora_tab
9
+ from library.class_lora_tab import LoRATools
10
+
11
+ import os
12
+ from library.custom_logging import setup_logging
13
+ from library.localization_ext import add_javascript
14
+
15
+ # Set up logging
16
+ log = setup_logging()
17
+
18
+
19
+ def UI(**kwargs):
20
+ add_javascript(kwargs.get("language"))
21
+ css = ""
22
+
23
+ headless = kwargs.get("headless", False)
24
+ log.info(f"headless: {headless}")
25
+
26
+ if os.path.exists("./style.css"):
27
+ with open(os.path.join("./style.css"), "r", encoding="utf8") as file:
28
+ log.info("Load CSS...")
29
+ css += file.read() + "\n"
30
+
31
+ if os.path.exists("./.release"):
32
+ with open(os.path.join("./.release"), "r", encoding="utf8") as file:
33
+ release = file.read()
34
+
35
+ if os.path.exists("./README.md"):
36
+ with open(os.path.join("./README.md"), "r", encoding="utf8") as file:
37
+ README = file.read()
38
+
39
+ interface = gr.Blocks(
40
+ css=css, title=f"Kohya_ss GUI {release}", theme=gr.themes.Default()
41
+ )
42
+
43
+ with interface:
44
+ with gr.Tab("Dreambooth"):
45
+ (
46
+ train_data_dir_input,
47
+ reg_data_dir_input,
48
+ output_dir_input,
49
+ logging_dir_input,
50
+ ) = dreambooth_tab(headless=headless)
51
+ with gr.Tab("LoRA"):
52
+ lora_tab(headless=headless)
53
+ with gr.Tab("Textual Inversion"):
54
+ ti_tab(headless=headless)
55
+ with gr.Tab("Finetuning"):
56
+ finetune_tab(headless=headless)
57
+ with gr.Tab("Utilities"):
58
+ utilities_tab(
59
+ train_data_dir_input=train_data_dir_input,
60
+ reg_data_dir_input=reg_data_dir_input,
61
+ output_dir_input=output_dir_input,
62
+ logging_dir_input=logging_dir_input,
63
+ enable_copy_info_button=True,
64
+ headless=headless,
65
+ )
66
+ with gr.Tab("LoRA"):
67
+ _ = LoRATools(headless=headless)
68
+ with gr.Tab("About"):
69
+ gr.Markdown(f"kohya_ss GUI release {release}")
70
+ with gr.Tab("README"):
71
+ gr.Markdown(README)
72
+
73
+ htmlStr = f"""
74
+ <html>
75
+ <body>
76
+ <div class="ver-class">{release}</div>
77
+ </body>
78
+ </html>
79
+ """
80
+ gr.HTML(htmlStr)
81
+ # Show the interface
82
+ launch_kwargs = {}
83
+ username = kwargs.get("username")
84
+ password = kwargs.get("password")
85
+ server_port = kwargs.get("server_port", 0)
86
+ inbrowser = kwargs.get("inbrowser", False)
87
+ share = False
88
+ server_name = kwargs.get("listen")
89
+
90
+ launch_kwargs["server_name"] = server_name
91
+ if username and password:
92
+ launch_kwargs["auth"] = (username, password)
93
+ if server_port > 0:
94
+ launch_kwargs["server_port"] = server_port
95
+ if inbrowser:
96
+ launch_kwargs["inbrowser"] = inbrowser
97
+ if share:
98
+ launch_kwargs["share"] = False
99
+ interface.launch(**launch_kwargs, share=False)
100
+
101
+
102
+ if __name__ == "__main__":
103
+ # torch.cuda.set_per_process_memory_fraction(0.48)
104
+ parser = argparse.ArgumentParser()
105
+ parser.add_argument(
106
+ "--listen",
107
+ type=str,
108
+ default="127.0.0.1",
109
+ help="IP to listen on for connections to Gradio",
110
+ )
111
+ parser.add_argument(
112
+ "--username", type=str, default="", help="Username for authentication"
113
+ )
114
+ parser.add_argument(
115
+ "--password", type=str, default="", help="Password for authentication"
116
+ )
117
+ parser.add_argument(
118
+ "--server_port",
119
+ type=int,
120
+ default=0,
121
+ help="Port to run the server listener on",
122
+ )
123
+ parser.add_argument("--inbrowser", action="store_true", help="Open in browser")
124
+ parser.add_argument("--share", action="store_true", help="Share the gradio UI")
125
+ parser.add_argument(
126
+ "--headless", action="store_true", help="Is the server headless"
127
+ )
128
+ parser.add_argument(
129
+ "--language", type=str, default=None, help="Set custom language"
130
+ )
131
+
132
+ parser.add_argument("--use-ipex", action="store_true", help="Use IPEX environment")
133
+
134
+ args = parser.parse_args()
135
+
136
+ UI(
137
+ username=args.username,
138
+ password=args.password,
139
+ inbrowser=args.inbrowser,
140
+ server_port=args.server_port,
141
+ share=False,
142
+ listen=args.listen,
143
+ headless=args.headless,
144
+ language=args.language,
145
+ )