|
import os |
|
import subprocess |
|
import requests |
|
import shutil |
|
from tqdm import tqdm |
|
|
|
cuda_url = "https://huggingface.co/datasets/NeuroDonu/PortableSource/resolve/main/CUDA_124.7z" |
|
updater_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster/updater.bat" |
|
start_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster/start_nvidia.bat" |
|
git_repo_url = "https://github.com/visomaster/VisoMaster" |
|
models_url = "https://huggingface.co/datasets/NeuroDonu/PortableVersions/resolve/main/visomaster_models.7z" |
|
ffmpeg_url = "https://github.com/visomaster/visomaster-assets/releases/download/v0.1.0_dp/ffmpeg.exe" |
|
|
|
base_dir = os.path.dirname(os.path.abspath(__file__)) |
|
visomaster_dir = os.path.join(base_dir, "Visomaster") |
|
cuda_archive_path = os.path.join(base_dir, "CUDA_124.7z") |
|
cuda_extract_dir = os.path.join(base_dir, "CUDA") |
|
seven_zip_path = os.path.join(base_dir, "7z.exe") |
|
git = os.path.join(base_dir, "git", "cmd", "git.exe") |
|
python = os.path.join(base_dir, "python", "python.exe") |
|
requirements = os.path.join(visomaster_dir, "requirements_cu124.txt") |
|
updater_bat = os.path.join(base_dir, "updater.bat") |
|
start_bat = os.path.join(base_dir, "start_nvidia.bat") |
|
ffmpeg_path = os.path.join(visomaster_dir, "dependencies", "ffmpeg.exe") |
|
pip_cmd = [python, "-m", "pip", "install", "uv"] |
|
uv_cmd = [python, "-m", "uv", "pip", "install"] |
|
models_path = os.path.join(visomaster_dir, "model_assets") |
|
models_name = os.path.join(models_path, "visomaster_models.7z") |
|
cuda_bin_path = os.path.join(base_dir, "CUDA", "bin") |
|
cuda_lib_path = os.path.join(base_dir, "CUDA", "lib") |
|
|
|
def clear_terminal(): |
|
os.system('cls' if os.name == 'nt' else 'clear') |
|
|
|
def download_with_requests(url, destination): |
|
response = requests.get(url, stream=True, headers={"User-Agent": "Mozilla/5.0"}) |
|
total_size = int(response.headers.get("content-length", 0)) |
|
block_size = 16384 |
|
progress_bar = tqdm(total=total_size, unit="B", unit_scale=True, desc=f"Скачивание {os.path.basename(destination)}") |
|
with open(destination, "wb") as file: |
|
for data in response.iter_content(block_size): |
|
progress_bar.update(len(data)) |
|
file.write(data) |
|
progress_bar.close() |
|
|
|
def extract_archive(archive_path, extract_dir): |
|
subprocess.run([seven_zip_path, "x", archive_path, f"-o{extract_dir}", "-y"], check=True) |
|
|
|
def clone_git_repo(repo_url, clone_dir): |
|
if os.path.exists(clone_dir): |
|
return |
|
subprocess.run([git, "clone", repo_url, clone_dir], check=True) |
|
|
|
def setup_cuda_paths(): |
|
if os.path.exists(cuda_bin_path) and os.path.exists(cuda_lib_path): |
|
current_path = os.environ.get("PATH", "") |
|
os.environ["PATH"] = f"{cuda_bin_path};{cuda_lib_path};{current_path}" |
|
|
|
def install_requirements(): |
|
uv_torch = [uv_cmd, "torch==2.4.1", "torchvision", "torchaudio", "--index-url", "https://download.pytorch.org/whl/cu124"] |
|
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"] |
|
dependencies = [ |
|
"numpy==1.26.4", |
|
"opencv-python==4.10.0.84", |
|
"scikit-image==0.21.0", |
|
"pillow==9.5.0", |
|
"onnx==1.16.1", |
|
"protobuf==4.23.2", |
|
"psutil==6.0.0", |
|
"onnxruntime-gpu==1.20.0", |
|
"packaging==24.1", |
|
"PySide6==6.7.2", |
|
"kornia", |
|
"tqdm", |
|
"ftfy", |
|
"regex", |
|
"pyvirtualcam==0.11.1", |
|
"numexpr", |
|
"onnxsim", |
|
"requests", |
|
"pyqt-toast-notification==1.3.2", |
|
"qdarkstyle", |
|
"pyqtdarktheme" |
|
] |
|
subprocess.run(uv_torch, check=True) |
|
subprocess.run(uv_tensorrt, check=True) |
|
for dependency in dependencies: |
|
subprocess.run(uv_cmd + dependency.split(), check=True) |
|
|
|
def download_bat(): |
|
download_with_requests(updater_url, updater_bat) |
|
download_with_requests(start_url, start_bat) |
|
|
|
def download_ffmpeg(): |
|
download_with_requests(ffmpeg_url, ffmpeg_path) |
|
|
|
def download_models(): |
|
if not os.path.exists(models_path): |
|
os.makedirs(models_path) |
|
download_with_requests(models_url, models_name) |
|
extract_archive(models_name, models_path) |
|
|
|
def has_safetensors_files(directory): |
|
for filename in os.listdir(directory): |
|
if filename.endswith(".safetensors"): |
|
return True |
|
return False |
|
|
|
if __name__ == "__main__": |
|
clear_terminal() |
|
if not os.path.exists(cuda_extract_dir): |
|
download_with_requests(cuda_url, cuda_archive_path) |
|
extract_archive(cuda_archive_path, cuda_extract_dir) |
|
os.remove(cuda_archive_path) |
|
if not os.path.exists(visomaster_dir): |
|
clone_git_repo(git_repo_url, visomaster_dir) |
|
|
|
setup_cuda_paths() |
|
install_requirements() |
|
if not os.path.exists(updater_bat) or os.path.exists(start_bat): |
|
download_bat() |
|
if not os.path.exists(ffmpeg_path): |
|
download_ffmpeg() |
|
|
|
if has_safetensors_files(models_path): |
|
pass |
|
else: |
|
download_models() |
|
|
|
clear_terminal() |
|
|
|
print("Установка завершена!") |