NeuroDonu commited on
Commit
7d22bc3
·
verified ·
1 Parent(s): b35a135

Update visomaster/visomaster_install.py

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