ACCC1380 commited on
Commit
2055d6d
1 Parent(s): c54149b

Upload lora-scripts/gui.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. lora-scripts/gui.py +82 -0
lora-scripts/gui.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import locale
3
+ import os
4
+ import platform
5
+ import subprocess
6
+ import sys
7
+
8
+ from mikazuki.launch_utils import (base_dir_path, catch_exception,
9
+ prepare_environment)
10
+ from mikazuki.log import log
11
+
12
+ parser = argparse.ArgumentParser(description="GUI for stable diffusion training")
13
+ parser.add_argument("--host", type=str, default="127.0.0.1")
14
+ parser.add_argument("--port", type=int, default=28000, help="Port to run the server on")
15
+ parser.add_argument("--listen", action="store_true")
16
+ parser.add_argument("--skip-prepare-environment", action="store_true")
17
+ parser.add_argument("--disable-tensorboard", action="store_true")
18
+ parser.add_argument("--disable-tageditor", action="store_true")
19
+ parser.add_argument("--tensorboard-host", type=str, default="127.0.0.1", help="Port to run the tensorboard")
20
+ parser.add_argument("--tensorboard-port", type=int, default=6006, help="Port to run the tensorboard")
21
+ parser.add_argument("--localization", type=str)
22
+ parser.add_argument("--dev", action="store_true")
23
+
24
+
25
+ @catch_exception
26
+ def run_tensorboard():
27
+ log.info("Starting tensorboard...")
28
+ subprocess.Popen([sys.executable, "-m", "tensorboard.main", "--logdir", "logs",
29
+ "--host", args.tensorboard_host, "--port", str(args.tensorboard_port)])
30
+
31
+
32
+ @catch_exception
33
+ def run_tag_editor():
34
+ log.info("Starting tageditor...")
35
+ cmd = [
36
+ sys.executable,
37
+ base_dir_path() / "mikazuki/dataset-tag-editor/scripts/launch.py",
38
+ "--port", "28001",
39
+ "--shadow-gradio-output",
40
+ "--root-path", "/proxy/tageditor"
41
+ ]
42
+ if args.localization:
43
+ cmd.extend(["--localization", args.localization])
44
+ else:
45
+ l = locale.getdefaultlocale()[0]
46
+ if l and l.startswith("zh"):
47
+ cmd.extend(["--localization", "zh-Hans"])
48
+ subprocess.Popen(cmd)
49
+
50
+
51
+ def launch():
52
+ log.info("Starting SD-Trainer Mikazuki GUI...")
53
+ log.info(f"Base directory: {base_dir_path()}, Working directory: {os.getcwd()}")
54
+ log.info(f'{platform.system()} Python {platform.python_version()} {sys.executable}')
55
+
56
+ if not args.skip_prepare_environment:
57
+ prepare_environment()
58
+
59
+ os.environ["MIKAZUKI_HOST"] = args.host
60
+ os.environ["MIKAZUKI_PORT"] = str(args.port)
61
+ os.environ["MIKAZUKI_TENSORBOARD_HOST"] = args.tensorboard_host
62
+ os.environ["MIKAZUKI_TENSORBOARD_PORT"] = str(args.tensorboard_port)
63
+ os.environ["MIKAZUKI_DEV"] = "1" if args.dev else "0"
64
+
65
+ if args.listen:
66
+ args.host = "0.0.0.0"
67
+ args.tensorboard_host = "0.0.0.0"
68
+
69
+ if not args.disable_tageditor:
70
+ run_tag_editor()
71
+
72
+ if not args.disable_tensorboard:
73
+ run_tensorboard()
74
+
75
+ import uvicorn
76
+ log.info(f"Server started at http://{args.host}:{args.port}")
77
+ uvicorn.run("mikazuki.app:app", host=args.host, port=args.port, log_level="error")
78
+
79
+
80
+ if __name__ == "__main__":
81
+ args, _ = parser.parse_known_args()
82
+ launch()