44import sys
55import zipfile
66import shutil
7-
87sys .path .append (os .path .dirname (os .path .abspath (__file__ )))
98
9+ ascii_logo = """
10+ __ ___ _ _ _
11+ \ \ / (_) __| | ___ ___ | | (_)_ __ __ _ ___
12+ \ \ / /| |/ _` |/ _ \/ _ \| | | | '_ \ / _` |/ _ \
13+ \ V / | | (_| | __/ (_) | |___| | | | | (_| | (_) |
14+ \_/ |_|\__,_|\___|\___/|_____|_|_| |_|\__, |\___/
15+ |___/
16+ """
17+
1018def install_package (* packages ):
1119 subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , * packages ])
1220
13- install_package ("requests" , "rich" , "ruamel.yaml" )
14- from core .pypi_autochoose import main as choose_mirror
15-
1621def check_gpu ():
17- """检查是否有 NVIDIA GPU 可用"""
1822 try :
19- # 🔍 尝试运行 nvidia-smi 命令来检测 GPU
2023 subprocess .run (['nvidia-smi' ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , check = True )
2124 return True
2225 except (subprocess .CalledProcessError , FileNotFoundError ):
2326 return False
2427
2528def main ():
29+ install_package ("requests" , "rich" , "ruamel.yaml" )
2630 from rich .console import Console
2731 from rich .panel import Panel
28-
32+ from rich . box import DOUBLE
2933 console = Console ()
34+
35+ width = max (len (line ) for line in ascii_logo .splitlines ()) + 4
36+ welcome_panel = Panel (
37+ ascii_logo ,
38+ width = width ,
39+ box = DOUBLE ,
40+ title = "[bold green]🌏[/bold green]" ,
41+ border_style = "bright_blue"
42+ )
43+ console .print (welcome_panel )
44+
3045 console .print (Panel .fit ("🚀 开始安装" , style = "bold magenta" ))
3146
3247 # 配置镜像源
33- console . print ( Panel ( "⚙️ 正在配置镜像源" , style = "bold yellow" ))
48+ from core . pypi_autochoose import main as choose_mirror
3449 choose_mirror ()
3550
36- # 检测系统和 GPU
51+ # 检测系统和GPU
3752 if platform .system () == 'Darwin' :
38- console .print (Panel ("🍎 检测到 MacOS,正在安装 CPU 版本的 PyTorch... 但速度会慢很多 " , style = "cyan" ))
39- subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "torch" , "torchaudio" ])
53+ console .print (Panel ("🍎 检测到 MacOS,正在安装 CPU 版本的 PyTorch... 但转写速度会慢很多 " , style = "cyan" ))
54+ subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "torch==2.1.2 " , "torchaudio==2.1.2 " ])
4055 else :
4156 has_gpu = check_gpu ()
4257 if has_gpu :
4358 console .print (Panel ("🎮 检测到 NVIDIA GPU,正在安装 CUDA 版本的 PyTorch..." , style = "cyan" ))
4459 subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "torch==2.0.0" , "torchaudio==2.0.0" , "--index-url" , "https://download.pytorch.org/whl/cu118" ])
4560 else :
46- console .print (Panel ("💻 未检测到 NVIDIA GPU,正在安装 CPU 版本的 PyTorch... 但速度会慢很多 " , style = "cyan" ))
47- subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "torch" , "torchaudio" ])
61+ console .print (Panel ("💻 未检测到 NVIDIA GPU,正在安装 CPU 版本的 PyTorch... 但转写速度会慢很多 " , style = "cyan" ))
62+ subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "torch==2.1.2 " , "torchaudio==2.1.2 " ])
4863
4964 # 安装 WhisperX
5065 console .print (Panel ("📦 正在安装 WhisperX..." , style = "cyan" ))
@@ -65,6 +80,10 @@ def install_requirements():
6580 subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "-r" , "requirements.txt" ])
6681
6782 def download_and_extract_ffmpeg ():
83+ # 需要同时安装 conda-ffmpeg 和 ffmpeg.exe
84+ console .print (Panel ("📦 正在通过 conda 安装 ffmpeg..." , style = "cyan" ))
85+ subprocess .check_call (["conda" , "install" , "-y" , "ffmpeg" ])
86+
6887 import requests
6988 system = platform .system ()
7089 if system == "Windows" :
@@ -83,15 +102,15 @@ def download_and_extract_ffmpeg():
83102 print (f"{ ffmpeg_exe } 已存在" )
84103 return
85104
86- print (" 正在下载 FFmpeg" )
105+ console . print (Panel ( "📦 正在下载 FFmpeg..." , style = "cyan" ) )
87106 response = requests .get (url )
88107 if response .status_code == 200 :
89108 filename = "ffmpeg.zip" if system in ["Windows" , "Darwin" ] else "ffmpeg.tar.xz"
90109 with open (filename , 'wb' ) as f :
91110 f .write (response .content )
92- print (f"FFmpeg 下载完成: { filename } " )
111+ console . print (Panel ( f"FFmpeg 下载完成: { filename } " , style = "cyan" ) )
93112
94- print (" 正在解压 FFmpeg" )
113+ console . print (Panel ( "📦 正在解压 FFmpeg..." , style = "cyan" ) )
95114 if system == "Linux" :
96115 import tarfile
97116 with tarfile .open (filename ) as tar_ref :
@@ -106,15 +125,15 @@ def download_and_extract_ffmpeg():
106125 zip_ref .extract (file )
107126 shutil .move (os .path .join (* file .split ('/' )[:- 1 ], os .path .basename (file )), os .path .basename (file ))
108127
109- print (" 正在清理" )
128+ console . print (Panel ( "📦 正在清理..." , style = "cyan" ) )
110129 os .remove (filename )
111130 if system == "Windows" :
112131 for item in os .listdir ():
113132 if os .path .isdir (item ) and "ffmpeg" in item .lower ():
114133 shutil .rmtree (item )
115- print ("FFmpeg 解压完成" )
134+ console . print (Panel ( "FFmpeg 解压完成" , style = "cyan" ) )
116135 else :
117- print (" FFmpeg 下载失败" )
136+ console . print (Panel ( "❌ FFmpeg 下载失败", style = "red" ) )
118137
119138 def install_noto_font ():
120139 if platform .system () == 'Linux' :
0 commit comments