Upload visomaster_install.py
Browse files- NeuroDonu/visomaster_install.py +132 -0
NeuroDonu/visomaster_install.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import requests
|
| 4 |
+
import shutil
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
|
| 7 |
+
cuda_url = "https://huggingface.co/datasets/NeuroDonu/PortableSource/resolve/main/CUDA_124.7z"
|
| 8 |
+
updater_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster/updater.bat"
|
| 9 |
+
start_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster/start_nvidia.bat"
|
| 10 |
+
git_repo_url = "https://github.com/visomaster/VisoMaster"
|
| 11 |
+
models_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster_models.7z"
|
| 12 |
+
ffmpeg_url = "https://github.com/visomaster/visomaster-assets/releases/download/v0.1.0_dp/ffmpeg.exe"
|
| 13 |
+
|
| 14 |
+
base_dir = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
+
visomaster_dir = os.path.join(base_dir, "Visomaster")
|
| 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"]
|
| 27 |
+
models_path = os.path.join(visomaster_dir, "model_assets")
|
| 28 |
+
models_name = os.path.join(models_path, "visomaster_models.7z")
|
| 29 |
+
cuda_bin_path = os.path.join(base_dir, "CUDA", "bin")
|
| 30 |
+
cuda_lib_path = os.path.join(base_dir, "CUDA", "lib")
|
| 31 |
+
|
| 32 |
+
def clear_terminal():
|
| 33 |
+
os.system('cls' if os.name == 'nt' else 'clear')
|
| 34 |
+
|
| 35 |
+
def download_with_requests(url, destination):
|
| 36 |
+
response = requests.get(url, stream=True, headers={"User-Agent": "Mozilla/5.0"})
|
| 37 |
+
total_size = int(response.headers.get("content-length", 0))
|
| 38 |
+
block_size = 16384
|
| 39 |
+
progress_bar = tqdm(total=total_size, unit="B", unit_scale=True, desc=f"Скачивание {os.path.basename(destination)}")
|
| 40 |
+
with open(destination, "wb") as file:
|
| 41 |
+
for data in response.iter_content(block_size):
|
| 42 |
+
progress_bar.update(len(data))
|
| 43 |
+
file.write(data)
|
| 44 |
+
progress_bar.close()
|
| 45 |
+
|
| 46 |
+
def extract_archive(archive_path, extract_dir):
|
| 47 |
+
subprocess.run([seven_zip_path, "x", archive_path, f"-o{extract_dir}", "-y"], check=True)
|
| 48 |
+
|
| 49 |
+
def clone_git_repo(repo_url, clone_dir):
|
| 50 |
+
if os.path.exists(clone_dir):
|
| 51 |
+
return
|
| 52 |
+
subprocess.run([git, "clone", repo_url, clone_dir], check=True)
|
| 53 |
+
|
| 54 |
+
def setup_cuda_paths():
|
| 55 |
+
if os.path.exists(cuda_bin_path) and os.path.exists(cuda_lib_path):
|
| 56 |
+
current_path = os.environ.get("PATH", "")
|
| 57 |
+
os.environ["PATH"] = f"{cuda_bin_path};{cuda_lib_path};{current_path}"
|
| 58 |
+
|
| 59 |
+
def install_requirements():
|
| 60 |
+
uv_torch = [uv_cmd, "torch==2.4.1", "torchvision", "torchaudio", "--index-url", "https://download.pytorch.org/whl/cu124"]
|
| 61 |
+
uv_tensorrt = [uv_cmd, "tensorrt==10.6.0", "tensorrt-cu12_libs==10.6.0", "tensorrt-cu12_bindings==10.6.0", "--index-url", "https://pypi.nvidia.com"]
|
| 62 |
+
dependencies = [
|
| 63 |
+
"numpy==1.26.4",
|
| 64 |
+
"opencv-python==4.10.0.84",
|
| 65 |
+
"scikit-image==0.21.0",
|
| 66 |
+
"pillow==9.5.0",
|
| 67 |
+
"onnx==1.16.1",
|
| 68 |
+
"protobuf==4.23.2",
|
| 69 |
+
"psutil==6.0.0",
|
| 70 |
+
"onnxruntime-gpu==1.20.0",
|
| 71 |
+
"packaging==24.1",
|
| 72 |
+
"PySide6==6.7.2",
|
| 73 |
+
"kornia",
|
| 74 |
+
"tqdm",
|
| 75 |
+
"ftfy",
|
| 76 |
+
"regex",
|
| 77 |
+
"pyvirtualcam==0.11.1",
|
| 78 |
+
"numexpr",
|
| 79 |
+
"onnxsim",
|
| 80 |
+
"requests",
|
| 81 |
+
"pyqt-toast-notification==1.3.2",
|
| 82 |
+
"qdarkstyle",
|
| 83 |
+
"pyqtdarktheme"
|
| 84 |
+
]
|
| 85 |
+
subprocess.run(uv_torch, check=True)
|
| 86 |
+
subprocess.run(uv_tensorrt, check=True)
|
| 87 |
+
for dependency in dependencies:
|
| 88 |
+
subprocess.run(uv_cmd + dependency.split(), check=True)
|
| 89 |
+
|
| 90 |
+
def download_bat():
|
| 91 |
+
download_with_requests(updater_url, updater_bat)
|
| 92 |
+
download_with_requests(start_url, start_bat)
|
| 93 |
+
|
| 94 |
+
def download_ffmpeg():
|
| 95 |
+
download_with_requests(ffmpeg_url, ffmpeg_path)
|
| 96 |
+
|
| 97 |
+
def download_models():
|
| 98 |
+
if not os.path.exists(models_path):
|
| 99 |
+
os.makedirs(models_path)
|
| 100 |
+
download_with_requests(models_url, models_name)
|
| 101 |
+
extract_archive(models_name, models_path)
|
| 102 |
+
|
| 103 |
+
def has_safetensors_files(directory):
|
| 104 |
+
for filename in os.listdir(directory):
|
| 105 |
+
if filename.endswith(".safetensors"):
|
| 106 |
+
return True
|
| 107 |
+
return False
|
| 108 |
+
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
clear_terminal()
|
| 111 |
+
if not os.path.exists(cuda_extract_dir):
|
| 112 |
+
download_with_requests(cuda_url, cuda_archive_path)
|
| 113 |
+
extract_archive(cuda_archive_path, cuda_extract_dir)
|
| 114 |
+
os.remove(cuda_archive_path)
|
| 115 |
+
if not os.path.exists(visomaster_dir):
|
| 116 |
+
clone_git_repo(git_repo_url, visomaster_dir)
|
| 117 |
+
|
| 118 |
+
setup_cuda_paths()
|
| 119 |
+
install_requirements()
|
| 120 |
+
if not os.path.exists(updater_bat) or os.path.exists(start_bat):
|
| 121 |
+
download_bat()
|
| 122 |
+
if not os.path.exists(ffmpeg_path):
|
| 123 |
+
download_ffmpeg()
|
| 124 |
+
|
| 125 |
+
if has_safetensors_files(models_path):
|
| 126 |
+
pass
|
| 127 |
+
else:
|
| 128 |
+
download_models()
|
| 129 |
+
|
| 130 |
+
clear_terminal()
|
| 131 |
+
|
| 132 |
+
print("Установка завершена!")
|