Boka73 commited on
Commit
d441a93
·
verified ·
1 Parent(s): 5a5dda1

create installer.py

Browse files
Files changed (1) hide show
  1. Installer.py +85 -0
Installer.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import glob
3
+ import os
4
+ import shutil
5
+ import site
6
+ import subprocess
7
+ import sys
8
+
9
+
10
+ script_dir = os.getcwd()
11
+
12
+
13
+ def run_cmd(cmd, capture_output=False, env=None):
14
+ # Run shell commands
15
+ return subprocess.run(cmd, shell=True, capture_output=capture_output, env=env)
16
+
17
+
18
+ def check_env():
19
+ # If we have access to conda, we are probably in an environment
20
+ conda_not_exist = run_cmd("conda", capture_output=True).returncode
21
+ if conda_not_exist:
22
+ print("Conda is not installed. Exiting...")
23
+ sys.exit()
24
+
25
+ # Ensure this is a new environment and not the base environment
26
+ if os.environ["CONDA_DEFAULT_ENV"] == "base":
27
+ print("Create an environment for this project and activate it. Exiting...")
28
+ sys.exit()
29
+
30
+
31
+ def install_dependencies():
32
+ global MY_PATH
33
+
34
+ # Install Git and clone repo
35
+ run_cmd("conda install -y -k git")
36
+ run_cmd("git clone https://codeberg.org/roop-unleashed/roop-unleashed.git")
37
+ os.chdir(MY_PATH)
38
+ run_cmd("git checkout main")
39
+ # Installs dependencies from requirements.txt
40
+ run_cmd("python -m pip install -r requirements.txt")
41
+
42
+
43
+ def update_dependencies():
44
+ global MY_PATH
45
+
46
+ os.chdir(MY_PATH)
47
+ # do a hard reset for to update even if there are local changes
48
+ run_cmd("git fetch --all")
49
+ run_cmd("git reset --hard origin/main")
50
+ run_cmd("git pull")
51
+ # Installs/Updates dependencies from all requirements.txt
52
+ run_cmd("python -m pip install -r requirements.txt")
53
+
54
+
55
+ def start_app():
56
+ global MY_PATH
57
+
58
+ os.chdir(MY_PATH)
59
+ # forward commandline arguments
60
+ sys.argv.pop(0)
61
+ args = " ".join(sys.argv)
62
+ print("Launching App")
63
+ run_cmd(f"python run.py {args}")
64
+
65
+
66
+ if __name__ == "__main__":
67
+ global MY_PATH
68
+
69
+ MY_PATH = "roop-unleashed"
70
+
71
+ # Verifies we are in a conda environment
72
+ check_env()
73
+
74
+ # If webui has already been installed, skip and run
75
+ if not os.path.exists(MY_PATH):
76
+ install_dependencies()
77
+ else:
78
+ # moved update from batch to here, because of batch limitations
79
+ updatechoice = input("Check for Updates? [y/n]").lower()
80
+ if updatechoice == "y":
81
+ update_dependencies()
82
+
83
+ # Run the model with webui
84
+ os.chdir(script_dir)
85
+ start_app()