Upload visomaster_install.py
Browse files- visomaster/visomaster_install.py +108 -0
visomaster/visomaster_install.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
import urllib.request
|
4 |
+
|
5 |
+
aria2c_url = "https://huggingface.co/datasets/NeuroDonu/PortableSource/resolve/main/aria2c.exe"
|
6 |
+
cuda_url = "https://huggingface.co/datasets/NeuroDonu/PortableSource/resolve/main/CUDA_124.7z"
|
7 |
+
updater_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster/updater.bat"
|
8 |
+
start_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster/start_nvidia.bat"
|
9 |
+
git_repo_url = "https://github.com/visomaster/VisoMaster"
|
10 |
+
models_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster_models.7z"
|
11 |
+
ffmpeg_url = "https://github.com/visomaster/visomaster-assets/releases/download/v0.1.0_dp/ffmpeg.exe"
|
12 |
+
|
13 |
+
base_dir = os.path.dirname(os.path.abspath(__file__))
|
14 |
+
visomaster_dir = os.path.join(base_dir, "Visomaster")
|
15 |
+
aria2c_exe_path = os.path.join(base_dir, "aria2c.exe")
|
16 |
+
cuda_archive_path = os.path.join(base_dir, "CUDA_124.7z")
|
17 |
+
cuda_extract_dir = os.path.join(base_dir, "CUDA")
|
18 |
+
seven_zip_path = os.path.join(base_dir, "7z.exe")
|
19 |
+
git = os.path.join(base_dir, "git", "cmd", "git.exe")
|
20 |
+
python = os.path.join(base_dir, "python", "python.exe")
|
21 |
+
requirements = os.path.join(visomaster_dir, "requirements_cu124.txt")
|
22 |
+
updater_bat = os.path.join(base_dir, "updater.bat")
|
23 |
+
start_bat = os.path.join(base_dir, "start_nvidia.bat")
|
24 |
+
ffmpeg_path = os.path.join(visomaster_dir, "dependencies", "ffmpeg.exe")
|
25 |
+
pip_cmd = [python, "-m", "pip", "install", "uv"]
|
26 |
+
uv_cmd = [python, "-m", "uv", "pip", "install", "-r"]
|
27 |
+
models_path= os.path.join(visomaster_dir, "model_assets")
|
28 |
+
models_name= os.path.join(models_path, "visomaster_models.7z")
|
29 |
+
|
30 |
+
cuda_bin_path = os.path.join(base_dir, "CUDA", "bin")
|
31 |
+
cuda_lib_path = os.path.join(base_dir, "CUDA", "lib")
|
32 |
+
|
33 |
+
|
34 |
+
def download_with_urllib(url, destination):
|
35 |
+
with urllib.request.urlopen(url) as response, open(destination, 'wb') as out_file:
|
36 |
+
shutil.copyfileobj(response, out_file)
|
37 |
+
|
38 |
+
def download_with_aria2c(url, destination,):
|
39 |
+
subprocess.run(
|
40 |
+
[
|
41 |
+
aria2c_exe_path,
|
42 |
+
"-d", os.path.dirname(destination),
|
43 |
+
"-o", os.path.basename(destination),
|
44 |
+
"-j", "16",
|
45 |
+
"-x", "16",
|
46 |
+
url
|
47 |
+
],check=True)
|
48 |
+
|
49 |
+
def extract_archive(archive_path, extract_dir):
|
50 |
+
subprocess.run([seven_zip_path, "x", archive_path], check=True)
|
51 |
+
|
52 |
+
def clone_git_repo(repo_url, clone_dir):
|
53 |
+
if os.path.exists(clone_dir):
|
54 |
+
return
|
55 |
+
try:
|
56 |
+
subprocess.run([git, "clone", repo_url, clone_dir], check=True)
|
57 |
+
except subprocess.CalledProcessError as e:
|
58 |
+
exit(1)
|
59 |
+
|
60 |
+
def modify_requirements_file(file_path):
|
61 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
62 |
+
content = file.read()
|
63 |
+
modified_content = content.replace("--extra-index-url", "--index-url")
|
64 |
+
with open(file_path, 'w', encoding='utf-8') as file:
|
65 |
+
file.write(modified_content)
|
66 |
+
|
67 |
+
def setup_cuda_paths():
|
68 |
+
if os.path.exists(CUDA_BIN_PATH) and os.path.exists(CUDA_LIB_PATH):
|
69 |
+
current_path = os.environ.get("PATH", "")
|
70 |
+
os.environ["PATH"] = f"{CUDA_BIN_PATH};{CUDA_LIB_PATH};{current_path}"
|
71 |
+
|
72 |
+
def install_requirements():
|
73 |
+
subprocess.run([pip_cmd])
|
74 |
+
subprocess.run([uv_cmd, requirements])
|
75 |
+
|
76 |
+
def download_bat():
|
77 |
+
download_with_urllib(updater_url, updater_bat)
|
78 |
+
download_with_urllib(start_url, start_bat)
|
79 |
+
|
80 |
+
def ffmpeg():
|
81 |
+
download_with_urllib(ffmpeg_url, ffmpeg_path)
|
82 |
+
|
83 |
+
def download_models():
|
84 |
+
download_with_aria2c(models_url, models_name)
|
85 |
+
extract_archive(models_name, models_path)
|
86 |
+
|
87 |
+
if __name__ == "__main__":
|
88 |
+
if not os.path.exists(aria2c_exe_path):
|
89 |
+
download_with_urllib(aria2c_url, aria2c_exe_path)
|
90 |
+
if not os.path.exists(cuda_archive_path):
|
91 |
+
download_with_aria2c(cuda_url, cuda_archive_path, aria2c_exe_path)
|
92 |
+
if not os.path.exists(cuda_extract_dir):
|
93 |
+
extract_archive(cuda_archive_path, seven_zip_path)
|
94 |
+
if os.path.exists(cuda_extract_dir):
|
95 |
+
os.remove(cuda_archive_path)
|
96 |
+
|
97 |
+
clone_git_repo(git_repo_url, visomaster_dir)
|
98 |
+
setup_cuda_paths()
|
99 |
+
modify_requirements_file(requirements)
|
100 |
+
install_requirements()
|
101 |
+
if not os.path.exists(start_bat):
|
102 |
+
download_bat()
|
103 |
+
if not os.path.exists(ffmpeg_path):
|
104 |
+
ffmpeg()
|
105 |
+
if not os.path.exists(models_path):
|
106 |
+
download_models()
|
107 |
+
|
108 |
+
print("Установка завершена!")
|